Hi all--
This issue is completely perplexing me, the following is code that reads in lines from a file and is supposed to copy each line into an array:
Code:
235 char* buffer = malloc(sizeof(1024));
236 char** fileStrings = malloc(sizeof(1024)*40);
237 FILE* redirFile = file_open(argvec[j+1]);
238
239 j=0;
240 for(buffer = file_getline(buffer, redirFile); buffer != NULL;
241 buffer = file_getline(buffer,redirFile)) {
242 buffer = chomp(buffer);
243 fprintf(stderr, "Buffer:%s\n", buffer);
244 fileStrings[j]=buffer;
245 fprintf(stderr, "First element:%s\n", fileStrings[0]);
246 fprintf(stderr, "Second element:%s\n", fileStrings[1]);
247 j++;
248 }
The following is the output from this code snippet:
Code:
Buffer:1
First element:1
Second element:(null)
Buffer:2
First element:2
Second element:2
What the heck is going on here?