Advertisement
cd62131

Scanf

Feb 21st, 2014
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include<stdio.h>
  2. typedef struct {
  3.   char name[100];
  4.   int age;
  5.   char sex;
  6. } PERSONAL;
  7. void personal_input(PERSONAL data[]);
  8. void personal_output(PERSONAL data[]);
  9. int main(void) {
  10.   PERSONAL data[3];
  11.   personal_input(data);
  12.   personal_output(data);
  13.   return 0;
  14. }
  15. void personal_input(PERSONAL data[]) {
  16.   int i;
  17.   for (i = 0; i < 3; i++) {
  18.     printf("名前:");
  19.     scanf("%99[^\n]%*[^\n]", data[i].name);
  20.     getchar();
  21.     printf("年齢:");
  22.     scanf("%d%*c", &data[i].age);
  23.     printf("性別:");
  24.     scanf("%c%*c", &data[i].sex);
  25.   }
  26. }
  27.  
  28. void personal_output(PERSONAL data[]) {
  29.   int i;
  30.   for (i = 0; i < 3; i++) {
  31.     printf("名前:%s\n", data[i].name);
  32.     printf("年齢:%d\n", data[i].age);
  33.     printf("性別:%c\n", data[i].sex);
  34.   }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement