错误 (Id) 返回 1 个退出状态
Error(Id) returned 1 exit status
我试图遍历单向链表的程序,出现错误,似乎这样做,而循环没有正确应用,请检查
该程序在下面,我试图使用do和指针进行遍历。
#include<stdio.h>
#include<stdlib.h>
int main()
{
char ch;
struct node
{
int info;
struct node *next;
};
typedef struct node node;
node *start, *ptr, *ne;
ptr=NULL;
int count=0;
do
{
ne=(node*) malloc(sizeof(node));
printf("nEnter Data: ");
scanf("%d",&ne->info);
if(ptr!=NULL)
{
ptr->next=ne;
ptr=ptr->next;
}
else {
start=ne;
ptr=ne;
}
printf("nDo you wish to continue?n ");
scanf("%c",&ch);
}while(ch=='y'|| ch=='Y');
ptr->next=NULL;
printf("The linked list is: ");
ptr=start;
while(ptr!=NULL)
{
printf("t%d",&ptr->info);
ptr=ptr->next;
count++;
}
printf("nTotal number of elements: %d",count);
return(0);
}
更改
printf("t%d",&ptr->info);
自
printf("t%d",ptr->info);
另外,我不建议在typedef struct node node;
中使用相同的名称"节点"但这仍然不是问题。
编辑:
我还发现您的代码存在问题:
改变
printf("nDo you wish to continue?n ");
scanf("%c",&ch);
自
printf("nDo you wish to continue?n ");
getchar();
scanf("%c",&ch);
或
您也可以将其更改为
printf("nDo you wish to continue?n ");
scanf(" %c",&ch); //add a space before %c
为什么这会导致错误?
在程序中,当您尝试使用 'printf((' 打印任何内容时,缓冲区中会留下一个空格,因此我们必须读取它并忽略它,否则 ch 将被分配空格。要读取空格并忽略,如上所述,我们有两个选择。尝试任何一个。
相关文章:
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- 为什么系统函数总是在C++中返回已转移的退出状态?
- C++ 中的编译错误:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 编译问题:在函数"_start"中:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 试图在崇高中奔跑. 错误 已发生: 收集2.exe: 错误: ld 返回 1 退出状态
- collect2:错误:ld 返回 1 个退出状态未定义的引用
- C++ collect2:错误:ld 返回 1 退出状态
- 找不到 -llibmysqld Collect2.exe:错误:ld 返回 1 退出状态
- 每次我要使用外部资源时,我都会得到:collect2。exe:错误 ld 返回 1 退出状态
- 当出现错误ld return 1退出状态时,如何编译程序
- 无法访问 Arduino 结构字段。错误"退出状态 1。xxxx 不命名类型"
- "Extern"对象问题:错误:Id 返回 1 个退出状态
- c++ (C::B) 错误:ld 返回 1 个退出状态
- 在 c++ 中捕获 shell 脚本退出状态
- 对"displayForStudent(int, int const*, double const*, int)"的未定义引用 collect2.exe:错误:ld 返回 1 个退出状态
- 使用类[错误] LD返回1退出状态
- 如何解决退出状态 1 错误
- 错误 (Id) 返回 1 个退出状态
- 退出状态 1 令牌之前的预期主表达式'.'
- 错误:LD返回1个退出状态-CodeBlocks