#include <stdio.h>
#include <string.h>
struct Directory {
char Name;
long int Number;
int HouseNumber;
char street;
};
int main(void)
{
struct Directory contact;
struct Directory *answer1, *answer2, *answer3, *answer4;
char answer;
printf("Welcome to Telephone Directory.\n\nPlease enter the name of the contact.\n");
scanf("%s", &contact.Name);
printf("Please enter the number of the contact.\n");
scanf("%ld", &contact.Number);
printf("Please enter the address of the contact.\n");
scanf("%d %s", &contact.HouseNumber, &contact.street);
answer1 = &contact;
answer2 = &contact;
answer3 = &contact;
answer4 = &contact;
printf("Would you like to obtain information on your contact? Enter 'yes' or 'no'.\n");
scanf("%s", &answer);
if (strcmp(&answer, "yes")==0) {
printf("%s\n", &answer1->Name);
printf("%ld\n", answer2->Number);
printf("%d", answer3->HouseNumber);
printf("%s", &answer4->street);
}
if (strcmp(&answer, "no")==0) {
printf("Thank you for using Telephone Directory.\n");
}
}
C で連絡先プログラムを作成しようとしています。プログラムにユーザーの家の住所を出力させたいのです。構造体に「HouseNumber」変数と構造体に「street」変数があり、「answer3」を int 変数として設定して「HouseNumber」を表示し、「answer4」を char 変数として設定して「street」を表示します。一緒に、私は彼らがユーザーの住所を単一の文字列で出力することを望んでいましたが、プログラムを実行し、番地と通りを入力した後に連絡先情報を表示するために「はい」と入力すると、プログラムがクラッシュし、lldb が悪い形式で表示されます。スレッドエラー。私のコンパイラはコードに問題はないと言っているので、すべてが正しいように見えますが、クラッシュします。誰かがこれで私を助けてくれますか?