0
#include<stdio.h>
struct student{
char name[80];
char subject
char country;

};

int main(){
struct student s[10];
int i;
printf("Enter the information of the students:\n");
for(i=0;i<4;++i)
{
printf("\nEnter name of the student: ");
scanf("%s",&s[i].name);
printf("\nEnter the subject of the student: ");
scanf("%s",&s[i].subject);
printf("\nEnter name of the student country: ");
scanf("%s",&s[i].country);
}
printf("\n showing the input of student information: \n");
for(i=0;i<10;++i)
{
printf("\nName: \n");
puts(s[i].name);
printf("\nMajor: \n",s[i].subject);
printf("\nCountry: \n",s[i].country);
}
return 0;
}

***結果を表示しようとしましたが、件名と国が表示されません。コーディングの問題を教えてください。

4

3 に答える 3

1

件名と国が表示されていませんか、それとも最初の文字のみが表示されていますか?

私はCに慣れていませんが、変更することをお勧めします

char variableName 

char variableName[size]

名前にはあるが、国と主題にはありません。それがあなたの問題であるかどうかはわかりませんが、おそらく char variableName だけがユーザー入力の1文字しか格納しないと思います。

于 2013-11-13T21:01:18.497 に答える
0

変換パターンを提供する必要がありますchar%c

printf("\nMajor: %c\n",s[i].subject);
printf("\nCountry: %c\n",s[i].country);

また

scanf("%s",&s[i].name); 

は正しくありません。

scanf("%s", s[i].name); // s[i].name is already an array

文字を読み取るには、正しい変換パターンも渡す必要があります

scanf("%c", &s[i].subject);
scanf("%c", &s[i].country);
于 2013-11-13T20:53:34.390 に答える
0

あなたstructは次のようになるはずです:

struct student{
char name[80];
char subject[80];
char country[80];
};
于 2013-11-13T21:04:05.200 に答える