P
Psibur
Hello, trying to get back into c and was having issue with reading a
simple text file with an aribtrary # of lines with 3 int's per line,
with the eventual purpose of putting each int into an element of an
array (eventually will be other things, but I'm sticking to int's for
now). I.e.:
0 1 1
1 1 1
2 1 1 etc...
The problem is it'll read and print all but the last line. Is there
something I'm forgetting about an End Of Line or EOF with fscanf? If
it means anything, I'm using gcc on win32 (djgpp) and haven't been
able to compile it under Linux yet (if there's much difference.) Here
is the minimalist version of the code with all the fault protection
and good stuff taken out for brevity:
#include <stdio.h>
int main() {
char buff[BUFSIZ];
FILE *infile;
int nums[10];
infile = fopen("a.dat", "r");
fscanf(infile, "%d %d %d\n", &nums[0],&nums[1], &nums[2]);
while (!feof(infile)) {
/*future home of parsing junk*/
printf("%d %d %d\n", nums[0], nums[1], nums[2]);
fscanf(infile, "%d %d %d\n", &nums[0], &nums[1], &nums[2]);
}
fclose(infile);
return 0;
}
Much appreciation in advance.
simple text file with an aribtrary # of lines with 3 int's per line,
with the eventual purpose of putting each int into an element of an
array (eventually will be other things, but I'm sticking to int's for
now). I.e.:
0 1 1
1 1 1
2 1 1 etc...
The problem is it'll read and print all but the last line. Is there
something I'm forgetting about an End Of Line or EOF with fscanf? If
it means anything, I'm using gcc on win32 (djgpp) and haven't been
able to compile it under Linux yet (if there's much difference.) Here
is the minimalist version of the code with all the fault protection
and good stuff taken out for brevity:
#include <stdio.h>
int main() {
char buff[BUFSIZ];
FILE *infile;
int nums[10];
infile = fopen("a.dat", "r");
fscanf(infile, "%d %d %d\n", &nums[0],&nums[1], &nums[2]);
while (!feof(infile)) {
/*future home of parsing junk*/
printf("%d %d %d\n", nums[0], nums[1], nums[2]);
fscanf(infile, "%d %d %d\n", &nums[0], &nums[1], &nums[2]);
}
fclose(infile);
return 0;
}
Much appreciation in advance.