我正在尝试创建一个包含一些基本信息的结构数组。我的代码如下:
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;
int main(void) {
int i, customer_number, _zip, _accountId;
struct Customer customer_list[9];
char _firstName[30], _lastName[30], _street[35], _city[20], _state[3], _phone[15];
for (i = 0; i < 10; i++) {
customer_number = 0;
printf("Enter data for customer %d: \n", customer_number);
printf("Enter First Last Phone: ");
scanf("%s%s%s", &_firstName, &_lastName, &_phone);
printf("\nEnter Address (Street City State ZIP): ");
scanf("%s%s%s%d", &_street, &_city, &_state, &_zip);
Customer customer_list[i] = {[i].firstName = _firstName}
}
return 0;
}
看起来这应该有效,但我收到的错误是&#34;我必须有恒定的价值&#34;任何人都可以把我推向正确的方向吗?谢谢!
答案 0 :(得分:1)
<span data-audio-file-url="{{ AUDIO_FILES_URL }}{{ audio_file_path }}">{{ audio_file_description }}</span>
此行必须
Customer customer_list[i] = {[i].firstName = _firstName}
编辑:作业应由strcpy(customer_list[i].firstName, _firstName);