我正在嘗試做一些練習編程,並且對於我來說,這是一個難題。檢查結構,如果不在結構中添加項目。 C
問題是我應該編寫一個程序,將採取「進入」並將其放置在結構中的汽車的品牌和型號,如果製造模型不在那裏,否則它什麼也不做。
這是我到目前爲止,我不斷收到錯誤:
#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);
}
在結構汽車定義後移動addCar函數的函數聲明 – 999k