Я пытаюсь написать C код. Он работает правильно до GPA, но не продолжается и завершается после ввода GPA. Я не понимаю его причину. Что я должен сделать, чтобы решить эту проблему?
Вот мои коды:
NODE* create_list()
{
NODE *first, *temp = 0, *newNode;
first = 0;
int choice = 1;
head = (NODE *)malloc(sizeof(NODE));
if (head == NULL)
{
printf("Unable to allocate memory.");
}
else
{
printf("Do you want to continue(Type 0 or 1)?\n");
scanf_s("%d", &choice);
while (choice)
{
newNode = (NODE *)malloc(sizeof(NODE));
struct studentType studen;
printf("Enter the data student Id:\n");
scanf_s("%d", &studen.id);
printf("Enter the data student Name:\n");
scanf_s("%s", studen.name);
printf("Enter the data student GPA:\n");
scanf_s("%d", &studen.GPA);
newNode->stud = studen; // Link data field of newNode with data
newNode->ptr = NULL; // Link address field of newNode with NULL
temp->ptr = newNode; // Link previous node i.e. temp to the newNode
temp = temp->ptr;
printf("Do you want to continue(Type 0 or 1)?\n");
scanf_s("%d", &choice);
}
}
temp->ptr = 0;
return first;
}