输入
1021202
2022310
8102134
1030912
3110203
4021205
#
没有结果输出,统计二三位是02正常应该是3
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
char code[8];
struct node *next;
};
int main(void){
struct node *head,*p;
int count=0,size=sizeof(struct node);
char str[8];
head=NULL;
gets(str);
while(strcmp(str,"#")!=0){
p=(struct node *)malloc (size);
strcpy(p->code,str);
head=p->next;
head=p;
gets(str);
}
for(p=head;p->next!=NULL;p=p->next)
if(p->code[1]=='0'&&p->code[2]=='2')
count++;
printf("%d\n",count);
return 0;
}
C语言统计专业人数未解出
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
CSDN专家-link 2021-07-04 11:29关注head=p->next;
head=p;
这样写肯定是不行啊。head赋值两遍算啥啊。应该是p->next = head; head = p;本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报