#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define RECORDS 2
int main() {
typedef struct {
char firstName[30];
char lastName[30];
char street[35];
char city[20];
char state[3];
int zip;
char phone[15];
int accountId;
} Customer ;
Customer customerArray[RECORDS];
typedef int records;
records i = 0;
printf("================================================================\n");
for(i = 0; i < RECORDS; ++i)
{
printf("Enter data for customer %d\n", i + 1);
printf("Enter firstname, last name, phone\n");
scanf("%s %s %s", customerArray[i].firstName, customerArray[i].lastName, customerArray[i].phone);
scanf("%*c");
printf("Enter Address (Street City State ZIP\n");
scanf("%s %s %s %d", customerArray[i].street, customerArray[i].city, customerArray[i].state, &customerArray[i].zip);
scanf("%*c");
}
for(i = 0; i < RECORDS; ++i) {
char input[3]= {'\0'};
printf("please enter state:\n");
scanf("%s",input);
int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n);
char *custstate = customerArray[i].state;
char *statelookup = input;
if (strcmp(custstate, statelookup) == 0) {
printf("\nData for customer number:%s", customerArray[i].accountId);
printf("\nAccount:%s", customerArray[i].accountId);
printf("\n Name:%s %s",customerArray[i].firstName, customerArray[i].lastName);
printf("\nAddress:%s %s %s %d",customerArray[i].street, customerArray[i].city, customerArray[i].state, customerArray[i].zip);
printf("\nPhone:%s",customerArray[i].phone);
}
else
printf("Could not find a match");
}
return 0;
}
无法弄清楚为什么该结构的一个成员没有正确递增。帐户 ID 产生不准确的输出。而且客户编号也没有正确生产。例如 1、2 等。
所述成员的输出看起来像这样......
客户编号数据:1606416396 账户:1606416396
它应该是什么样子
客户 1 帐户 1 的数据
不知道我做错了什么。仍在学习 C. 完全菜鸟。任何帮助将不胜感激!
我在想我必须终止成员。但不确定这是不是真的,甚至是如何。