存在死循环
时间: 2024-02-13 19:59:41 浏览: 14
好的,根据您的反馈,我为您提供修改方案:
在程序中存在死循环的原因是第26行的输入语句有误,应该将`%d`改为`%s`,代码修改如下:
```
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LEN sizeof(struct staff)
struct staff {
int num;
char name[20];
char station[10];
int score;
struct staff *next;
};
int main() {
struct staff *h, *p, *q;
int num;
char s[10];
h=(struct staff*)malloc(LEN);
h->next=NULL;//建立带头结点的空链表
scanf("%d",&num);
q=h;
while(num!=0)
{
p=(struct staff*)malloc(LEN);
p->num=num;
scanf("%s %s %d",p->name,p->station,&p->score);
p->next=NULL;
q->next=p;
q=p;
scanf("%d",&num);
}//输入数据到0截止
scanf("%s",s);
p=h->next;
while(p!=NULL)
{
if(strcmp(p->station,s)!=0)
{
printf("%d %s %s %d\n",p->num,p->name,p->station,p->score);
}
p=p->next; // 每次循环结束需要将p指向下一个结点
}
return 0;
}
```
这样,程序就可以正常运行了。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)