gpt4 book ai didi

c - C-当程序到达某个方法时,它才结束,为什么呢?

转载 作者:行者123 更新时间:2023-12-03 08:19:31 24 4
gpt4 key购买 nike

因此,我正在编写一个程序,该程序具有菜单选项,用户可以从中选择要插入,计数,打印,删除和修改节点的位置。用户还有第六个选择可以退出程序。我的问题是,只要用户选择第5个选项(即修改学生节点),程序就会突然结束,而不是返回菜单。为什么会这样,我该如何解决?

这是修改功能,无法正常运行:

void modifyStudentNode()
{
int id = 0;
struct student *ptr, *prev, *currPtr;
if(start==NULL)
{
printf("\nStudent List does not contain data\n");
}
else
{
printf("\nPlease enter the student ID of the student whose records you wish to modify: \n");
scanf("%d",&id);
fflush(stdin);
for(currPtr = start; (currPtr)&&((currPtr->student_id)!= id); prev = currPtr, currPtr = currPtr->next);

if(currPtr == NULL)
printf("\nStudent not Found\n");
else
{
printf("\nCurrent values for Student Id %d are: ", id);
printf("Student Name: %s\n", currPtr->student_name);
printf("Student GPA: %.2f\n", currPtr->gpa);
printf("Student Date of Registration: %d/%d/%d\n\n", currPtr->dt_of_reg.month,currPtr->dt_of_reg.day,currPtr->dt_of_reg.year);
printf("\nEnter modified values for Student Id %d: \n", id);
printf("Enter Student's Modified Name:\n");
scanf("%[^\t\n]s",&currPtr->student_name);
fflush(stdin);
printf("Enter Student's Modified GPA:\n");
scanf("%f",&currPtr->gpa);
fflush(stdin);
printf("Enter Student's Modified Date of Registration (mm/dd/yyyy):\n");
scanf("%d/%d/%d", &currPtr->dt_of_reg.month,currPtr->dt_of_reg.day,currPtr->dt_of_reg.year);
fflush(stdin);
}
}
}

最佳答案

你的线

scanf("%d/%d/%d", &currPtr->dt_of_reg.month,currPtr->dt_of_reg.day,currPtr->dt_of_reg.year);

应该
scanf("%d/%d/%d", &currPtr->dt_of_reg.month, &currPtr->dt_of_reg.day, &currPtr->dt_of_reg.year);

您忘记为最后两个数字添加 &

关于c - C-当程序到达某个方法时,它才结束,为什么呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60982306/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com