【发布时间】:2014-07-07 16:12:01
【问题描述】:
我当前的程序如下所示。这个程序应该询问一个人的 5 条记录并显示它们。
#include<stdio.h>
struct rec {
char name[100],address[100];
double age,mobileno;
}x;
main()
{
int i;
clrscr();
for(i=1;i<=5;i++)
{
printf("Enter Your Name: ");
scanf("%s",&x.name);
printf("Enter Your Age: ");
scanf("%lf",&x.age);
printf("Enter Your Address: ");
scanf("%s",&x.address);
printf("Enter Your Mobile No.: ");
scanf("%lf",&x.mobileno);
}
printf("\n\nThe Information has been added");
printf("\n\nNAME AGE ADDRESS MOBILE NUMBER");
for(i=1;i<=5;i++)
{
printf("\n%s %.0lf %s %.0lf",x.name,x.age,x.address,x.mobileno);
}
getch();
}
我在显示 5 条不同的记录时遇到问题。如何在一个 printf 中显示 5 条记录?
【问题讨论】:
-
不要将手机号码存储为双。双打是不精确的,在某些国家还需要前导 0。
-
您的核心问题是您有一个
struct rec变量x,您试图在其中存储5 个不同的值,并希望以后能够检索所有五个。变量只能存储一个值。你需要了解和使用数组。 -
我应该使用什么?还是用手机号做?
标签: c data-structures struct