【发布时间】:2015-09-20 18:58:44
【问题描述】:
我目前正在编写一个简单的代码,它重复读取用户输入并将输入存储到一个结构中,然后将它们打印出来。我在阅读“accountNum”和“balance”时遇到问题。编译器给出的警告是由于预期的不同参数的类型。 (*int/*double 与 int/double)。 我尝试使用 gets() 但无济于事。我希望对此有所了解。
另外,我是否在打印功能期间正确访问了元素?提前致谢!
#include <stdio.h>
#include <string.h>
struct account {
struct
{
char lastName[10];
char firstName[10];
} names;
int accountNum;
double balance;
};
void nextCustomer(struct account *acct);
void printCustomer(struct account acct);
int main()
{
struct account record;
int flag = 0;
do {
nextCustomer(&record);
if ((strcmp(record.names.firstName, "End") == 0) &&
(strcmp(record.names.lastName, "Customer") == 0))
flag = 1;
if (flag != 1)
printCustomer(record);
} while (flag != 1);
}
void nextCustomer(struct account *acct) {
printf("Enter names: (firstName lastName): " );
scanf("%s%s", acct->names.firstName, acct->names.lastName);
printf("Enter account number: ");
scanf("%d", acct->accountNum);
printf("Enter balance : ");
scanf("%lf", acct->balance);
}
void printCustomer(struct account acct) {
printf("%s%s %d %lf", acct.names.firstName, acct.names.lastName ,acct.accountNum,acct.balance);
}
【问题讨论】: