Problem with fgets and rewind function ..

Hello Friends,

I got stuck with fgets () & rewind() function .. Please need help..

Actually I am doing a like,
The function should read lines from a txt file until the function is called..
If the data from the txt file ends then it goes to the top and then again when the function is called it should display me the top row .. I am doing like below , But it's not doing what I am expecting

Please need help..

#include <stdio.h>
 
FILE* fileopen();
void read_line(void*);
 
void read_line(void *fh){
              char s[50];
              int i,n;
                            if( fgets(s,49,fh) != NULL) {
                                n = 0;
                                    while(isspace(s[n])){
                                        n++;
                                        if(s[n] == '/' && s[n++] == '/'){
                                                fgets(s,49,fh);
                                }
                             }
                                      printf("%s", s);
                            }
                            else{
                                    rewind(fh);
                            }
}
FILE* fileopen(){
          void *file = fopen("abc1.txt", "r");
            return file;
}
int main(void) {
           void *fh;
            int i;
              fh = fileopen();
               for(i = 0;i < 12; i++){
                 read_line(fh);
                }
              return 0;
}

abc1.txt

6  7
8 9
12 13

output

6  7
8 9
12 13
6  7
8 9
12 13
6  7
8 9
12 13

It should give me 12 rows as the function is called 12 times..
but it is returning me 9 rows..

How to solve it I am wondering from last couple of days ..Pls need help badly..

Regards,
prady

hey buddy

the problem in above code is fgets reads till EOF or new line.
after reading each line it is exiting and reading the next line ...

see below code which does what u wanted. actually i modified ur code and used fgetc instead of fgets

#include <stdio.h>

FILE* fileopen();
void read_line(void*);

void read_line(void *fh){
char s[50];
int i,n, char1;

    while\(\(char1 = fgetc\(fh\)\) != EOF\)\{
            printf\("%c", char1\);
    \}

rewind(fh);
}
FILE* fileopen(){
void *file = fopen("abc1.txt", "r");
return file;
}
int main(void) {
void *fh;
int i;
fh = fileopen();
for(i = 0;i <12; i++){
printf("calling : %d time\n", i);
read_line(fh);
}
return 0;
}