   confused?!? writing array to a file
  I have the following array :char codes [100] [15] = {0} ;I try to write it to a file with fwrite, but I don't know exactly how to deal with that function. For the moment I use :for (i=0; i<100; i++){   strcpy(codes[i], "000000000000000") ;printf("%s\n", codes[i]) ;fwrite(codes[i], sizeof(codes[i]), 1, fp) ;}and reading the array : for (i=0; i<100; i++){fread(codes[i], sizeof(codes[i]), 1, fp) ;printf("%d => %s\n", i, codes[i]) ;}[\source]is this correct, because I get strange things here :(  <SPAN CLASS=editedby>[edited by - Da Cobra on February 11, 2004 2:28:09 PM]</SPAN>
  You forgot to leave space for a terminating \0 in your strncpy. ;  Yeah... you're gonna get weirdness when you print... but the array probably has in it what you put in it if you look at it.  I imagine it's working, just the printf will give you garbage. [edited by - smitty1276 on February 11, 2004 6:46:39 PM];  Hey, by the way: for these arrays, you can use sizeof() on the whole array and you''ll get the right size. (that doesn''t work on dynamically allocated arrays though).So you can change the reading/writing code to this:// write the whole array in one fell swoopfwrite(codes, sizeof(codes), 1, fp);// and also read the whole array in one swoopfread(codes, sizeof(codes), 1, fp);  Shallow copying rules. 