I have the following function:
void writeResults(FILE* fp, FILE* fpw, Vector w, int size) {
Vector x;
while (1) {
char line[MAX_DIMENSION]; //max dimension is 200
if( (fgets(line,MAX_DIMENSION,fp)) == NULL) { //EOF
return;
}
else {
int i=0;
while (line[i]!='\0') {
printf("% d %c\n",i,line[i]); //print to check it
i++;
}
}
}
}
The line of the file it reads is:
1,1
2,2
However when I print each char until '\0' I get this output:
0 1
1 ,
2 1
3
4
0 2
1 ,
2 2
3
4
Does anyone have a clue as to why it reads the extra 3 and 4 chars? (there is no extra spaces in the file).
Note: the file was opened in the following way:
FILE* fp = fopen(fileIn, "r");
if (fp == NULL) {
perror("Couldn't open File");
exit(errno);
}