我正在尝试做一些练习编程,但对我来说,我遇到了一个难题。
问题是我应该编写一个程序,它将获取“输入”的汽车的品牌和型号并将其放置在结构中,如果制造模型不存在,否则它什么也不做。
这是我到目前为止所拥有的,并且我不断收到错误:
#include <stdio.h>
#include <string.h>
void addCar(struct car u, int* count, char *make[], char *model[]);
struct car { char make[30]; char model[30]; };
int main(void)
{
struct car unique[10] = {{"Ford", "Explorer"}, {"Honda", "Civic"},
{"Honda", "Accord"}, {"Chevy", "Malibu"}};
int i, count = 4;
addCar(unique, &count, "Ford", "Mustang");
}
void addCar(struct car u, int* count, char *make[], char *model[])
{
}
表示addCar(unique, &count,...
“参数类型struct car'
不完整”的行,最后一行表示“addCar 的冲突类型”
请各位大神指点一下好吗?
编辑:
好的,这就是我现在的代码,但我仍然无法让它工作。任何其他建议将不胜感激!
#include <stdio.h>
#include <string.h>
struct car { char make[30]; char model[30]; };
void addCar(struct car *u, int *count, char *make, char *model);
int main(void)
{
struct car unique[10] = {{"Ford", "Explorer"}, {"Honda", "Civic"},
{"Honda", "Accord"}, {"Chevy", "Malibu"}};
int i, count = 4;
printf("%s", unique[0].make);
addCar(unique, &count, "Ford", "Mustang");
}
void addCar(struct car *u, int *count, char *make, char *model)
{
int i = 0;
for (i; i < *count; i++)
{
if ((u[i].make != make) && (u[i].model != model))
{
strcpy(u->make, make);
strcpy(u->model, model);
count++;
}
}
for (i = 0; i < *count; i++)
printf("%s, %s", u[i].make, u[i].model);
}