Where as the same fine on Dev-C++ (TDM-GCC 4.8.1 64-bit Release), gcc version on centos is (gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-16)) Please tell me the reason for this:
Code:
#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;
}
}