一个很简单的问题,但我解决不了
下面程式的问题是当打入学校名字,但输出的是一个字元而不是我输入的学校名称字串程序代码:
#include <stdio.h> #include <stdlib.h> struct rating{ int rating_2011; int rating_2012; }; struct school{ char name[20]; struct rating rating; int school_num; }; int main () { char a[20]; int b,c,d; printf("plz enter your school name:\n"); scanf("%s",a); printf("plz enter your school rating in 2011:\n"); scanf("%d",&b); printf("plz enter your school rating in 2012:\n"); scanf("%d",&c); printf("plz enter your school number:\n"); scanf("%d",&d); struct school no1={a,{b,c},d}; struct school no2; no2=no1; printf("the name of your school is %s\n", no1.name); printf("the rating of %s in 2011 is %d\n",no1.name,no1.rating.rating_2011); printf("the rating of %s in 2012 is %d\n",no1.name,no1.rating.rating_2012); printf("the school number of %s is %d\n", no1.name,no1.school_num); printf("\n"); printf("the name of your school is %s\n", no2.name); printf("the rating of %s in 2011 is %d\n",no2.name,no2.rating.rating_2011); printf("the rating of %s in 2012 is %d\n",no2.name,no2.rating.rating_2012); printf("the school number of %s is %d\n", no2.name,no2.school_num); printf("\n"); system("Pause"); return 0; }