私は多くの警告を受けています。コンパイルすると、セグメンテーションフォルトのコアがダンプされます。ポインタや宣言と関係があると確信しています。セグメンテーションフォールトコアが構造体でダンプされる
struct Item
{
char *type;
char *name;
double *price;
double quantity;
};
int main(){
struct Item cart[3];
struct Item book[4];
struct Item clothing[5];
struct Item sports[6];
book->name = "harry potter";
strcpy(book->price, "100");
clothing->name = "shirt";
strcpy(clothing->price, "15");
sports->name = "football";
strcpy(sports->price, "20");
scanf("enter Item %c", cart->type);
if (cart->type == "book"){
scanf("please enter quantity %d", book->quantity);
printf("%s %d %d", book->name, book->price, book->quantity);
}
if (cart->type == "clothing"){
scanf("please enter quantity %d", clothing->quantity);
printf("%s %d %d", clothing->name, clothing->price, clothing- >quantity);
}
if (cart->type == "sports"){
scanf("please enter quantity %d", sports->quantity);
printf("%s %d %d", sports->name, sports->price, sports->quantity);
}
}
違反はありませんが、このコードは、誰もが良い答えを提供するためにあまりにも多くの方法で壊れています。あなたが取り組んでいる書籍/クラスを再検討する必要があります。 – kfsone