【发布时间】:2015-05-06 15:15:57
【问题描述】:
在 Dev-C++(TDM-GCC 4.8.1 64-bit Release)上同样罚款,centos 上的 gcc 版本是(gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-16))。 请告诉我我的编码逻辑是否有任何错误或其他原因
`#include<stdio.h>
#include<stdlib.h>
struct node
{
int i;
struct node *next;
};
void main()
{
struct node *head,*temp,*p;
int d;
char ch;
printf("Do you want to enter data? Y/N");
scanf("%c",&ch);
fflush(stdin);
if((ch=='y')||(ch=='Y'))
{
printf("Enter your data: ");
scanf("%d",&d);
fflush(stdin);
head=(struct node *)malloc(sizeof(struct node));
head->i=d;
head->next=NULL;
}
p=head;
printf("Do you want to enter more data? Y/N");
scanf("%c",&ch);
fflush(stdin);
while((ch=='y')||(ch=='Y'))
{
temp=(struct node *)malloc(sizeof(struct node));
printf("Enter your data: ");
scanf("%d",&d);
fflush(stdin);
temp->i=d;
temp->next=NULL;
if(p->i>=temp->i)
{
temp->next=head;
head=temp;
}
else
{
while((p->next!=NULL)&&(p->next->i<temp->i))
{
p=p->next;
}
temp->next=p->next;
p->next=temp;
}
printf("Do you want to enter more data? Y/N");
scanf("%c",&ch);
fflush(stdin);
p=head;
}
while(p!=NULL)
{
printf("%d ",p->i);
p=p->next;
}
}`
【问题讨论】:
-
好的,现在解释你的问题。怎么了?是不是编译失败?是不是跑不起来了?你提供什么输入?哪里坏了?
-
这是第一次接受我的输入,之后它没有,并且程序在发布多行后停止工作,这里是:你想输入数据吗? Y/Ny Enter your data: 5 您想输入更多数据吗? Y/N5 {此处自动输入 5}
标签: c linux gcc compiler-errors linked-list