Click here to Skip to main content
16,018,418 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: how to save a file? Pin
gentleguy23-Jan-08 2:16
gentleguy23-Jan-08 2:16 
GeneralRe: how to save a file? Pin
CPallini23-Jan-08 2:20
mveCPallini23-Jan-08 2:20 
GeneralRe: how to save a file? Pin
gentleguy23-Jan-08 19:46
gentleguy23-Jan-08 19:46 
GeneralRe: how to save a file? Pin
CPallini23-Jan-08 21:04
mveCPallini23-Jan-08 21:04 
GeneralRe: how to save a file? Pin
gentleguy23-Jan-08 21:05
gentleguy23-Jan-08 21:05 
QuestionRe: how to save a file? Pin
CPallini23-Jan-08 21:12
mveCPallini23-Jan-08 21:12 
GeneralRe: how to save a file? Pin
gentleguy24-Jan-08 0:22
gentleguy24-Jan-08 0:22 
GeneralRe: how to save a file? Pin
CPallini24-Jan-08 0:49
mveCPallini24-Jan-08 0:49 
If I remember well, you have arrays of doubles.
I give you a really crude sample code working.
(1) Create 10 3x4 arrays, initialise them with random values, i.e.
int i, j, k;
double a[10][3][4];

for (i=0; i<10; i++)
  for (j=0; j<3; j++)
    for (k=0; k<4; k++)
      a[i][j][k] = (double)rand()/RAND_MAX;


(2) Store all of the elements of all the arrays inside a file, explicitely
exploiting our knowledge of array size (really poorly coding, indeed).
FILE * fp = fopen("arrays.bin","wb");
fwrite(a, sizeof(double), 10 * 3 * 4, fp);
fclose(fp);


(3) Retrieve all of the array values from file content to buil the new 10 3x4 arrays.
double b[10][3][4];
FILE * fp = fopen("arrays.bin","rb");
fread(b, sizeof(double), 10 * 3 * 4, fp);
fclose(fp);
// now b contains the same values the original arrays have.


(3) bis, retrieve the 7-th array from the file content
double c[3][4]; // we want to initialise c with the values of the original a[6] array
FILE * fp = fopen("arrays.bin","rb");
fseek(fp, sizeof(double) * 6 * 4 * 3, SEEK_SET); 
fread(c, sizeof(double), 3 * 4, fp);
fclose(fp);



hope that helps.
Smile | :)

If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.

[my articles]


GeneralRe: how to save a file? Pin
gentleguy24-Jan-08 1:32
gentleguy24-Jan-08 1:32 
QuestionRe: how to save a file? Pin
CPallini24-Jan-08 1:54
mveCPallini24-Jan-08 1:54 
QuestionRe: how to save a file? Pin
David Crow23-Jan-08 2:44
David Crow23-Jan-08 2:44 
Generalstd::fstream and std::transform about lower case question Pin
Maxwell Chen22-Jan-08 19:16
Maxwell Chen22-Jan-08 19:16 
GeneralProblem is solved. Pin
Maxwell Chen22-Jan-08 19:34
Maxwell Chen22-Jan-08 19:34 
GeneralRe: std::fstream and std::transform about lower case question Pin
Stephen Hewitt22-Jan-08 19:44
Stephen Hewitt22-Jan-08 19:44 
GeneralRe: std::fstream and std::transform about lower case question Pin
Maxwell Chen23-Jan-08 16:09
Maxwell Chen23-Jan-08 16:09 
GeneralRe: std::fstream and std::transform about lower case question Pin
Stephen Hewitt24-Jan-08 11:59
Stephen Hewitt24-Jan-08 11:59 
GeneralRe: std::fstream and std::transform about lower case question Pin
Maxwell Chen24-Jan-08 16:21
Maxwell Chen24-Jan-08 16:21 
GeneralRe: std::fstream and std::transform about lower case question Pin
Stephen Hewitt24-Jan-08 16:36
Stephen Hewitt24-Jan-08 16:36 
GeneralRe: std::fstream and std::transform about lower case question Pin
Maxwell Chen24-Jan-08 20:03
Maxwell Chen24-Jan-08 20:03 
QuestionHow to automate a server Pin
CodingLover22-Jan-08 18:53
CodingLover22-Jan-08 18:53 
Generalstd::map, std::for_each and boost::bind Pin
User 58385222-Jan-08 17:17
User 58385222-Jan-08 17:17 
GeneralRe: std::map, std::for_each and boost::bind Pin
Stephen Hewitt22-Jan-08 18:34
Stephen Hewitt22-Jan-08 18:34 
GeneralRe: std::map, std::for_each and boost::bind Pin
User 58385222-Jan-08 18:41
User 58385222-Jan-08 18:41 
GeneralRe: std::map, std::for_each and boost::bind Pin
Stephen Hewitt22-Jan-08 18:49
Stephen Hewitt22-Jan-08 18:49 
Questionproblem with memory allocation when trying to store a large table Pin
gluballs22-Jan-08 16:15
gluballs22-Jan-08 16:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.