I have a simple text file that contains this:
A B
B C
E X
C D
(newline here)
I want to capture the non-whitespace characters from the file and enter them into a char array. I get a segmentation fault with this:
1 2 3 4 5 6 7
char c;
fscanf(infile, "%c ", &c);
for( int i = 0; c != EOF; i++ ) {
vertArray[i] = c;
printf("%c ", c);
fscanf(infile, "%c ", &c);
} // for
I know it's an EOF problem because when I change the 'for' condition to something like i < 20, it almost works - except it'll read 'D' forever (i.e. with my printf, all the letters will print, but the last letter, 'D' is printed a bunch of times. How do I fix this? Thanks.
BTW - writing in C not C++ (but this should work for both anyway, right?)