My simple code for getting info from user & print the same works fine with Windows OS (on Dev C++) but But its not asking for string when run on Ubuntu (tried Terminal/Dev C++ via WINE/Code Blocks)
#include<stdio.h>
void display();
struct book
{
int isbn;
char name[25];
}b[5];
void PUSH()
{
int top;
for(top=0;top<5;top++)
{
printf("Enter the ISBN no:");
scanf("%d",&(b[top].isbn));
printf("Enter the name:");
fflush(stdin);
gets(b[top].name);
}
}
main()
{
PUSH();
display();
}
void display()
{
int i;
for(i=0;i<5;i++)
{
printf("----------------\nISBN no: %d",(b[i].isbn));
printf("\nBook Name: %s \n",(b[i].name));
}
printf("----------------\n");
}
void POP()
{
int i;
for(i=0;i<5;i++)
{
printf("----------------\nISBN no: %d",(b[i].isbn));
printf("\nBook Name: %s \n",(b[i].name));
}
printf("----------------\n");
}
Output on Ubuntu:
Enter the ISBN no:23
Enter the name:Enter the ISBN no:
After i input 23 it has to ask for the name of the book but its skipping that part & again asks for next isbn no.
After some blind retries I found that when gets(b[top].name); gets(b[top].name); was used twice like this it worked fine....
My question is why is it so.? How to make ubuntu compile & run programs that run fine on windows?