I am reading lines from a file and parsing them into tokens. I am storing the tokens into a string array. Everything works fine until I leave the while loop and try to access the data. It does not seem to exist outside the while loop.![]()
Code followed by output:
Here’s the ouputCode:char *src[15]; while(fgets(line, 100, r) != NULL) { /*Skip strings starting with #*/ if(line[0] != '#') { src[x] = (char *)strtok(line, delim); x++; fprintf(o, "inside while: %s\n", src[x-1]); } } for (k=0; k<15; k++) { fprintf(o, "outside while: %s\n", src[k]); }
inside while: 192.0.32
inside while: 192.0.34
outside while:
outside while:



LinkBack URL
About LinkBacks




). After exiting the while loop, the array still does not maintain the entries I copied into it.