I have a file that will be inputted like this
5
set 1 1
set 0 0
get 0 0
get 1 0
comp 1 0
Basically the first number is an unsigned short value and the subsequent lines are methods that my program will excecute. The numbers are separated by tabs
if(pFile != NULL){
int i = 0;
while(!feof(pFile)){
line++;
fgets(input, 512, pFile);
if(line == 1){
x = atoi(&input[0]);
}
if(input[0] == 'g'){
n = atoi(&input[4]);
get(x,n);
}
if(input[0] == 's'){
n = atoi(&input[4]);
v = atoi(&input[6]);
set(n,v);
}
if(input[0] == 'c'){
n = atoi(&input[5]);
comp(n);
}
// if(input[0] == '\n'){
// printf("hi\n" );
// continue;
// }
// printf("n is: %d\n", n);
// x ^= (1<<n);
}
printf("There were %d lines\n",line );
fclose(pFile);
}
That is essentially my entire main method. For some reason whenever I enter a new line at the end of the file, it makes the last method of the test file run twice. For example the comp method would run twice and would give one extra output. When I ensure that there is no new line character at the end of the last line of the file, my code works just fine. I don't understand why a new line character is messing with my program?? Can anyone advise me please.