#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;
}*当我试图显示结果时,它没有显示主题,country.Can u告诉我我的编码中有什么问题?
发布于 2013-11-14 05:01:18
它不显示主题和国家,还是只显示第一个字母?
我不熟悉C语言,但我建议你改变
char variableName 至
char variableName[size]你在名字上有,但在国家和主题上没有。我不确定这是否是你的问题,但可能是,我相信仅仅是char variableName就只能存储用户输入的一个字符。
发布于 2013-11-14 04:53:34
您需要提供一个转换模式,对于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-14 05:04:05
你的struct应该是这样的:
struct student{
char name[80];
char subject[80];
char country[80];
};https://stackoverflow.com/questions/19964041
复制相似问题