When I run the program the last data in the file gets displayed twice.
#include<stdio.h>?//heder
#include<conio.h>//header
int main(){//main
int cn,clas;//variable declaration
char fn[15],ln[15],pn[10],adds[15];//variable declaration
float mr;//variable declaration
int i=1;//variable declaration
FILE *fp;//file pointer declaration
fp=fopen("student.txt","r");// opening a file
if (fopen("student.txt","r") == NULL) {
printf("Error: file pointer is null.");
return 0;
}
while(! feof(fp) ){//here the program reads the data from file
fscanf(fp,"%d",&cn);
fscanf(fp,"%s",&fn);
fscanf(fp,"%s",&ln);
fscanf(fp,"%d",&clas);
fscanf(fp,"%s",&adds);
fscanf(fp,"%s",&pn);
fscanf(fp,"%f",&mr);
//from here the data is printed on output string
printf("%d",cn);printf("\n");
printf("%s",fn);printf("\n");
printf("%s",ln);printf("\n");
printf("%d",clas);printf("\n");
printf("%s",adds);printf("\n");
printf("%s",pn);printf("\n");
printf("%f",mr);printf("\n");
printf("\n");
printf("\n");
}
}
the file i acessed is this this is the file that i accesed and the output that the program gives is this the last one gets repeated this is output please help me with this