用了strcpy函数还是不行,谢谢大家的热心回应,我自己再试试
程序代码:
#include <stdio.h> #include <stdlib.h> #include <string.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; struct school no1; struct school no2; 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); strcpy(no1.name, a); no1.rating.rating_2011 = b; no1.rating.rating_2012 = c; no1.school_num = d; 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; }
plz enter your school name:
Tom
plz enter your school rating in 2011:
3
plz enter your school rating in 2012:
2
plz enter your school number:
456
the name of your school is Tom
the rating of Tom in 2011 is 3
the rating of Tom in 2012 is 2
the school number of Tom is 456
the name of your school is Tom
the rating of Tom in 2011 is 3
the rating of Tom in 2012 is 2
the school number of Tom is 456