Code:
#include<stdio.h>#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
struct StudentRecord {
char *courseName;
float Mark;
struct StudentRecord *next;
};
typedef struct StudentRecord *StudentRecordType;
typedef struct {
char *firstName;
char *lastName;
int idNumber;
StudentRecordType courses;
} StudentType;
struct classNodeStruct {
StudentType *aStudent;
struct classNodeStruct *next;
};
typedef struct classNodeStruct *ClassNodeType;
main()
{
ClassNodeType arxeio,first;
char *id;
FILE *pfile;
char *name;
char *lastname;
char *age,*number;
int intnumber,i;
pfile=fopen("data.txt","r");
if (pfile!=NULL)
{
number=(char *)malloc(42*sizeof(char));
fscanf(pfile,"%s",number);
intnumber=atoi(number);
first=NULL;
for (i=0; i<intnumber; i++)
{
arxeio=(struct classNodeStruct *)malloc(sizeof(struct classNodeStruct));
arxeio->aStudent=(StudentType *)malloc(sizeof(StudentType));
arxeio->aStudent->courses=(struct StudentRecord *)malloc(sizeof(struct StudentRecord));
arxeio->aStudent->firstName=(char *)malloc(42*sizeof(char));
arxeio->aStudent->lastName=(char *)malloc(42*sizeof(char));
id=(char *)malloc(42*sizeof(char));
fscanf(pfile,"%s %s %s",arxeio->aStudent->firstName,arxeio->aStudent->lastName,id);
arxeio->aStudent->idNumber=atoi(id);
arxeio->next=first;
first=arxeio;
}
for (arxeio=first; arxeio=NULL; arxeio->next=arxeio)
{
printf("\n %s \n %s \n %d \n ",arxeio->aStudent->firstName,arxeio->aStudent->lastName,arxeio->aStudent->idNumber);
}
fclose(pfile);
}
else
{
printf("could not find the file");
}
getchar();
}
the file data.txt contains the following text
"3
giannis dimitrakopoulos 14445
dimitris antonakis 12245
giannis kamenos 4598"
Why i cant print my list?