Hi ,
I am surprised with the output of structure program........
I have created a simple program of structure for student record.
Code:
#include<stdio.h>
#include<string.h>
struct student
{
int roll_no;
char name[25];
char city[25];
char course[10];
};
int main()
{
int number,i;
struct student s[22];
printf("\n STUDENT RECORD PROGRAME");
printf("\nEnter The No. Of Records to Enter");
scanf("%d",&number);
printf("\nEnter The Data Of students");
for(i= 1;i<=number; i++)
{
printf("\nEnter Name:");
fgets(s[i].name, sizeof(s[i].name), stdin);
printf("\nEnter Roll No.:");
scanf("%d",&s[i].roll_no);
printf("\nEnter City:");
fgets(s[i].city, sizeof(s[i].city), stdin);
printf("\nEnter Course:");
fgets(s[i].course, sizeof(s[i].course), stdin);
}
printf( "\n The Details Of Student Are:\n");
for(i= 1;i<=number; i++)
{
printf("\n Enter Name: %s",s[i].name);
printf("\nRoll No.:%d",s[i].roll_no);
printf("\n City:%s",s[i].city);
printf("\n Course:%s",s[i].course);
}
}
But When I run the program it doesn't ask for name i.e it's directly jump to roll No.....and when I enter roll no. then jump to course not asking for city..........
Please help me where I am wrong ????
Thanks