#include <stdio.h>
#include <stdlib.h>
#define NULL 0
struct student
{
int id;
char name[20];
float marks;
struct student *next
};
typedef struct student node;
void main()
{
node *head;
void read(node *p);
void create(node *p);
int count(node *p);
void print(node *p);
head=(node *)malloc(sizeof(node));
read(head);
}
void read(node *list)
{
FILE *fp;
char filename[30];
int i;
printf("input file name:");
scanf("%s",filename);
fp=fopen(filename,"r");
while(!feof(fp))
{
create_f(list,fp);
}
}
void create_f(node *list,FILE *fp )
{
fscanf(fp,"%s %d %f",
list->name,&list->id,&list->marks);
printf("%s \t%d \t%f\n",
list->name,list->id,list->marks);
list->next=(node*)malloc(sizeof(node));
return;
}
The file that supposed to be read is this:
but for some reasons it read the last line twice. Can anybody help me?
if you cannot open it here is the output:
input file name:input.txt.txt
student01 1 95.000000
student03 3 90.000000
student05 5 86.000000
student07 7 83.000000
student09 9 98.000000
student10 10 93.000000
student08 8 92.000000
student06 6 96.000000
student04 4 93.000000
student02 2 88.000000
student02 2 88.000000Process returned 16 (0x10) execution time : 4.043 s Press any key to continue.
1: