I'm using fgets to read the contents of a file line-by-line, this is the code:-
Code:
#include<stdio.h>
#include<string.h>
main(void){
FILE *in , *out;
char Names[10][17], temp[2];
int NP;
in = fopen("greedy.in","r");
out = fopen("greedy.out","w");
NP = atoi(fgets(temp, 2, in));
int i;
for (i = 0 ; i < NP +1 ; i++){
fgets(Names[i], sizeof Names , in);
/* if (strlen(Names[0])== 1 ){
i = 0;
} */
}
}
Now the problem I get is that although the first fgets works properly, the next fgets code takes the 1st line again and not the 2nd as it should. Is there something wrong in what I am doing above?
Thanks in advance.
Bookmarks