Advertisement
Guest User

struct-example-unfinished

a guest
Jan 14th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. /*
  2.  * to input the name and salary of 5 employees using structure and display in
  3.  * proper format:
  4. */
  5.  
  6. #include <stdio.h>
  7.  
  8.  
  9.  
  10. void getData(), putData();
  11.  
  12. struct employeeData
  13. {
  14.     int salary;
  15.     char name[50];
  16. };
  17.  
  18. struct employeeData employee[5];
  19.  
  20. int i;
  21.  
  22.  
  23. void main()
  24. {
  25.     getData();
  26.     putData();
  27. }
  28.  
  29. void getData()
  30. {
  31.     printf("Please enter the name and respective salary of 5 different employees.\n");
  32.    
  33.     for(i=0;i<5;i++)
  34.     {
  35.         printf("\n \n Name: ");
  36.         fgets(employee[i].name,50,stdin);    
  37.        
  38.         printf("\n Salary: ");
  39.         scanf("%d", &employee[i].salary);
  40.     }
  41.  
  42. }
  43.  
  44. void putData()
  45. {
  46.     printf("\n\n The following information was gathered:\n");
  47.    
  48.     printf("NAME \t\t\t\t\t SALARY \n");
  49.    
  50.     for(i=0;i<5;i++)
  51.     {
  52.         printf("%s \t\t\t\t\t %d \n", employee[i].name, employee[i].salary);
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement