I made a program which accepts strings (first/last names) but instead of a typical output of
Phil Snowken age 3 , i am getting
Phil
Snowken
age 3
#include <stdio.h>
#define N 10
struct data{
char fname[30];
char lname[30];
int age;
};
main()
{
int i;
struct data base[N];
for(i=0;i<N;i++){
printf("
-------------------------");
printf("
People Data(%d remaining)
",N-i);
printf("---------------------------
");
printf("
First Name ");
fgets(base[i].fname,30,stdin);
printf("
Last Name ");
fgets(base[i].lname,30,stdin);
printf("
Age ");
scanf(" %d",&(base[i].age));
fflush(stdin);
}
for(i=0;i<N;i++)
printf("%s %s Year:(%d)",base[i].fname,base[i].lname,base[i].age);
return 0;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…