1

私はプログラミングの練習をしようとしていますが、私にとって難しい問題に直面しました。

問題は、「入力」された車のメーカーとモデルを取得して構造に配置するプログラムを作成することになっていることです。モデルがそこにない場合は、それ以外の場合は何もしません。

これは私がこれまでに持っているものであり、エラーが発生し続けています:

#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);
}
4

3 に答える 3

1

の関数プロトタイプaddCarが定義されており、' struct car' を定義する前に ' 'を使用していますstruct car。のプロトタイプの上に構造定義を移動してみてくださいaddCar

于 2013-10-18T04:31:51.317 に答える