This is due on Thursday (about 8 exercises) using linked lists. This is not how I have my program structured I just trimmed down eveyrthing and got it to this just to test if it would work, but it's not. On the second run instead of going in thruh the list, the information that I enter on Temp overrides what Head has. I have been trying this the whole day and could not come up with an answer. Please help. (This time I won't delete my post right away, I promise)
Code:#include <stdio.h> #include <stdlib.h> typedef struct Student { int x; char nombre[30]; struct Student* Next; }Student; int main() { Student *Head=NULL; Student *Temp; Student *Temp2; Temp=(Student*)malloc(sizeof(Student)); Temp2=(Student*)malloc(sizeof (Student)); int choice; printf("Insert Info\n"); while (1) { printf("Press 1 to exit\n"); scanf("%d",&choice); if (choice==1) break; printf("Student's Name\n"); scanf("%s",&Temp->nombre); Temp->Next=NULL; if(Head==NULL) Head=Temp; else { Temp2=Head; while (Temp2->Next!=NULL) { Temp2=Temp2->Next; } Temp2->Next=Temp; } } return 0; }