fork download
  1. #include <stdio.h>
  2. typedef struct date
  3. {
  4. int year;
  5. int month;
  6. int day;
  7. }DATE;
  8. typedef struct student
  9. {
  10. long studentID; /* 学号 */
  11. char studentName[10]; /* 姓名 */
  12. char stuGender; /* 性别 */
  13. DATE birthday; /* 出生日期 */
  14. int score[4]; /* 4门课程的成绩 */
  15. }STUDENT;
  16. int main(void)
  17. {
  18. STUDENT stu1, stu2;
  19. int i;
  20. printf("Input a record:\n");
  21. scanf("%ld", &stu1.studentID);
  22. scanf("%s", stu1.studentName); /* 输入学生姓名,无需加& */
  23. scanf(" %c", &stu1.stuGender); /* %c前有一个空格 */
  24. scanf("%d", &stu1.birthday.year);
  25. scanf("%d", &stu1.birthday.month);
  26. scanf("%d", &stu1.birthday.day);
  27. for (i=0; i<4; i++)
  28. {
  29. scanf("%d", &stu1.score[i]);
  30. }
  31. stu2 = stu1; /* 同类型的结构体变量之间的赋值操作 */
  32. printf("&stu2 = %p\n", &stu2); /* 打印结构体变量stu2的地址 */
  33. printf("%10ld%8s%3c%6d/%02d/%02d%4d%4d%4d%4d\n",
  34. stu2.studentID, stu2.studentName, stu2.stuGender,
  35. stu2.birthday.year, stu2.birthday.month, stu2.birthday.day,
  36. stu2.score[0], stu2.score[1], stu2.score[2], stu2.score[3]);
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 5268KB
stdin
Standard input is empty
stdout
Input a record:
&stu2 = 0x7ffc48c4f830
         0     ���       0/1220868166/32764   1   0-4977716915413