【发布时间】:2020-07-26 11:16:27
【问题描述】:
我做了一个停车系统,我使用 void 功能输入车辆的信息。 但我不知道如何使用 void 将字符串放入结构中。
这是我的代码。 我的错在哪里?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct car {
char plate[10];
char model[20];
char color[10];
};
void main() {
struct car c[4];
AddCar(c[0], "43ds43", "ford", "blue");
ShowCar(c[0]);
return 0;
}
// I guess my mistake is here
void AddCar(struct car c, char p[10], char m[10], char r[10]) {
strcpy(c.plate, p);
strcpy(c.model, m);
strcpy(c.color, r);
}
void ShowCar(struct car c) {
printf("Plate: %s Model: %s Color: %s\n-------", c.plate, c.model, c.color);
}
【问题讨论】: