c9-11.c 962 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <stdio.h>
  2. struct
  3. {
  4. int num;
  5. char name[10];
  6. char sex;
  7. char job;
  8. union
  9. {int clas;
  10. char position[10];
  11. }category;
  12. }person[2];
  13. int main()
  14. {
  15. int i;
  16. for(i=0;i<2;i++)
  17. {printf("please enter the data of person:\n");
  18. scanf("%d %s %c %c", &person[i].num, &person[i].name,
  19. &person[i].sex, &person[i].job);
  20. if(person[i].job == 's')
  21. scanf("%d", &person[i].category.clas);
  22. else if(person[i].job == 't')
  23. scanf("%s", person[i].category.position);
  24. else
  25. printf("Input error!");
  26. }
  27. printf("\n");
  28. printf("No. name sex job class/position\n");
  29. for(i=0;i<2;i++)
  30. {
  31. if (person[i].job == 's')
  32. printf("%-6d%-10s%-4c%-4c%-10d\n",person[i].num, person[i].name,
  33. person[i].sex, person[i].job, person[i].category.clas);
  34. else
  35. printf("%-6d%-10s%-4c%-4c%-10s\n",person[i].num, person[i].name,
  36. person[i].sex, person[i].job, person[i].category.position);
  37. }
  38. return 0;
  39. }