if i do in this way where is my mistake thanks very much
this is my global struct pointer
struct student* tempNextPoint = NULL;
i create this function to insert data into link list
Code:
void insertDataIntolinkList(char *stufirstname,char *stulastname,int stuage, int sturollno, char *stuclasssection, int stutotalnumber, char *stupromotion){
struct student* tempStudentInfo = (struct student*)malloc(sizeof(student));
strcpy((*tempStudentInfo).studentFirstName,stufirstname);
strcpy((*tempStudentInfo).studentLastName,stulastname);
(*tempStudentInfo).studentAge = stuage;
(*tempStudentInfo).studentRollNo = sturollno;
strcpy((*tempStudentInfo).studentClassSection,stuclasssection);
(*tempStudentInfo).studentTotalNumber = stutotalnumber;
strcpy((*tempStudentInfo).studentPromotion,stupromotion);
(*tempStudentInfo).nextPoint = tempNextPoint;
tempNextPoint = tempStudentInfo;
}
and with this function i display all data but in output ity give me all the same data for all student in link list why ?
Code:
void displayAllStudentResult(){
struct student* tempPrintPoint = tempNextPoint;
while(tempPrintPoint != NULL){
printf("\t\t\n student first name is %s ",(*tempPrintPoint).studentFirstName);
printf("\t\t\n student last name is %s ",(*tempPrintPoint).studentLastName);
printf("\t\t\n student age is %d ",(*tempPrintPoint).studentAge);
printf("\t\t\n student roll number is %d ",(*tempPrintPoint).studentRollNo);
printf("\t\t\n student class section is %c ",(*tempPrintPoint).studentClassSection);
printf("\t\t\n student total number %d ",(*tempPrintPoint).studentTotalNumber);
printf("\t\t\n student promotion %s ",(*tempPrintPoint).studentPromotion);
tempPrintPoint = (*tempPrintPoint).nextPoint;
}
printf("\n");
}
and in my main i do this way
Code:
int studentNumber,num;
struct student *getStudentInfo;
getStudentInfo = (struct student*)malloc(sizeof(struct student));
printf("\t\t\n for how many student you want do this opration -> ");
scanf("%d",&studentNumber);
for(num = 1; num <= studentNumber; num++ ){
printf("\t\t\n enter student firstname (max 40 charecters ) ");
scanf("%s",&(getStudentInfo)->studentFirstName);
printf("\t\t\n enter student lastname (max 40 charecters ) ");
scanf("%s",&(getStudentInfo)->studentLastName);
printf("\t\t\n enter student age ");
scanf("%d",&(getStudentInfo)->studentAge);
printf("\t\t\n enter student roll number ");
scanf("%d",&(getStudentInfo)->studentRollNo);
printf("\t\t\n enter student class section (A,B,C,D ecc... ) ");
scanf("%s",&(getStudentInfo)->studentClassSection);
printf("\t\t\n enter student total number ");
scanf("%d",&(getStudentInfo)->studentTotalNumber);
printf("\t\t\n enter student promotion result (pass or fail) ");
scanf("%s",&(getStudentInfo)->studentPromotion);
}
insertDataIntolinkList((*getStudentInfo).studentFirstName,(*getStudentInfo).studentLastName,(*getStudentInfo).studentAge,(*getStudentInfo).studentRollNo,(*getStudentInfo).studentClassSection,(*getStudentInfo).studentTotalNumber,(*getStudentInfo).studentPromotion);
for(num=0;num<=studentNumber;num++){
displayAllStudentResult();
}
free(getStudentInfo);