0

I'm trying to create a circular linked list from file. But the compiler shows an error in the lines

fgets(curr->FullN.LastN,Lmax,f);
curr->FullN.LastN[strlen(curr->FullN.LastN)-1]='\0';

The error:

cannot convert FILE* to char* for argument 1 to char *fgets(char*, int, FILE*)

Here the function:

Student *build_stack(char Name[]){
    Student *tek,*stack,*curr;
    tek = NULL; //At the beginning the list is empty
    stack = tek;
    FILE *f;
    if(!(f = fopen(Name,"r"))) 
        puts("Oops! file not found");
    else{
        while(!feof(f)){
            curr = new Student;//memory allocation
            if (stack == NULL)
                stack = curr;
            fgets(curr->FullN.LastN,Lmax,f);
            curr->FullN.LastN[strlen(curr->FullN.LastN)-1]='\0'; CLR;
            fgets(curr->FullN.FirstN,Lmax,f);
            curr->FullN.FirstN[strlen(curr->FullN.FirstN)-1]='\0';
            fgets(curr->FullN.SecondN,Lmax,f);
            curr->FullN.SecondN[strlen(curr->FullN.SecondN)-1]='\0';
            fgets(curr->Group,Lmax,f);
            curr->Group[strlen(curr->Group)-1]='\0';
            curr->APerformance.Mean = 0;
            for(int i=0;i<5;i++){
                CLR;
                fscanf(f,"%f",&(curr->APerformance.B[i]));
                        curr->APerformance.Mean += curr->APerformance.B[i];
            }
            curr->APerformance.Mean /= 5.0;
            curr->next = tek;
            tek = curr;
        }
    }
    if(stack){
        stack->next = tek;
    }
    return stack;//pointer returns to the top of the stack
}
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
  • 3
    `curr = new Student;` is C++, not C. – Ian Abbott May 17 '17 at 16:27
  • I have never seen the instruction CLR; at the end of line 11 – Simone Cifani May 17 '17 at 16:34
  • Welcome to Stack Overflow. Please read the [About] and [Ask] pages soon, but even more importantly, please read about how to create an MCVE ([MCVE]). Note that [`while (!feof(file))` is always wrong](http://stackoverflow.com/questions/5431941/while-feof-file-is-always-wrong) — and this code is no exception. You'll need to error check each call to `fgets()` and to `fscanf()`. Note that the final `fscanf()` will leave a newline in the input, which will confuse the next `fgets()`. And your code is C++ — not C. It's C++ written like C, but the use of `new` means it is not C code. – Jonathan Leffler May 17 '17 at 17:06

0 Answers0