hello. im a newbie C user and im having a little trouble in these for loop of mine im using. the first iteration is all fine but on the second and succesive iterations the first gets statement is skipped. im making a program that would ask the user to input multiple informations for atleast 5 people. i was also asked to use structures.. here is the code i have come up so far.. ive been stuck in it for like 3 hours now....
somebody please help.. tnx
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,j;
struct date{
int month;
int day;
int year;
};
struct info
{
char idno[10];
char lastname[30];
char firstname[30];
char middlename[30];
struct date birthdate;
char gender[1];
char address[50];
int height_in_meters;
int weight_in_kgs;
};
struct info student[50];
struct info employee[50];
struct date today;
for(i=0;i<2;i++)
{
printf("Enter Information for Student %d: \n\n",i+1);
printf("Enter ID Number: ");
gets(student[i].idno);
printf("Enter Student Last Name: ");
gets(student[i].lastname);
printf("Enter First Name: ");
gets(student[i].firstname);
printf("Enter Middlename: ");
gets(student[i].middlename);
printf("Enter Address: ");
gets(student[i].address);
printf("Enter Birth Month(MM): ");
scanf("%d", &student[i].birthdate.month);
printf("Enter Birth Day(DD): ");
scanf("%d", &student[i].birthdate.day);
printf("Enter Birth Year: ");
scanf("%d", &student[i].birthdate.year);
printf("Enter Gender(M/F): ");
scanf("%s", &student[i].gender);
printf("Enter Height(m): ");
scanf("%d", &student[i].height_in_meters);
printf("Enter Weight(kgs): ");
scanf("%d", &student[i].weight_in_kgs);
printf("\n\n");
}
getch();
}
here is a screenshot of the output
as you can see the gets part for the line "Enter ID Number is skipped on the second iteration..