Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct worker
  6. {
  7.     char* surname;
  8.     char* name;
  9.     char* membership;
  10.     int age;
  11.     char* position;
  12.     double salary;
  13. };
  14.  
  15. int main()
  16. {
  17.     struct worker* uk[256];
  18.     char buff[128];
  19.     int age1;
  20.     double sal1;
  21.     int num;
  22.     FILE* fl;
  23.     char input_name[256];
  24.     int i  = 0;
  25.     while (1)
  26.     {
  27.         printf("-----------------------------------------------------------\n");
  28.         printf("1 - To assume the source database from the file\n");
  29.         printf("2 - To display the current contents of the database\n");
  30.         printf("3 - To add the worker\n");
  31.         printf("4 - To delete the workers\n");
  32.         printf("4 - To save the current database to the file and to show the database\n");
  33.         printf("5 - Exit\n");
  34.         printf("-----------------------------------------------------------\n");
  35.  
  36.         scanf("%d", &num);
  37.  
  38.         switch(num)
  39.         {
  40.         case 1:
  41.         {
  42.             printf("Please, enter the name of the file from where you want to read your database:\n");
  43.             scanf("%s", input_name);
  44.             if((fl = fopen(input_name, "rw")) == NULL)
  45.             {
  46.                 printf("Can't open the file. Try again.");
  47.                 exit(1);
  48.             }
  49.             while (fgets(buff, 64, fl) != NULL)
  50.             {
  51.                 uk[i] = (struct worker*) malloc(sizeof(struct worker));
  52.                 int length = strlen(buff);
  53.                 (*uk[i]).surname = (char*) malloc(length*sizeof(char) + 1);
  54.                 strcpy((*uk[i]).surname, buff);
  55.                 break;
  56.                /* fgets(buff, 64, fl);
  57.                 length = strlen(buff);
  58.                 (*uk[i]).name = (char*) malloc(length*sizeof(char) + 1);
  59.                 strcpy((*uk[i]).name, buff);
  60.  
  61.                 fgets(buff, 64, fl);
  62.                 length = strlen(buff);
  63.                 (*uk[i]).membership = (char*) malloc(length*sizeof(char) + 1);
  64.                 strcpy((*uk[i]).membership, buff);
  65.  
  66.                 fgets(buff, 16, fl);
  67.                 (*uk[i]).age = atoi(buff);
  68.  
  69.                 fgets(buff, 64, fl);
  70.                 length = strlen(buff);
  71.                 (*uk[i]).position = (char*) malloc(length*sizeof(char) + 1);
  72.                 strcpy((*uk[i]).position, buff);
  73.  
  74.                 fgets(buff, 16, fl);
  75.                 (*uk[i]).salary = atof(buff);*/
  76.                 i++;
  77.             }
  78.             break;
  79.         }
  80.         case 2:
  81.         {
  82.             for (int j = 0; j < i; j++)
  83.             {
  84.                 printf("%s", (*uk[j]).surname /*/*, %s %s\n%d\n%s\n%lf(*uk[i]).name, (*uk[i]).membership, (*uk[i]).age, (*uk[i]).position, (*uk[i]).salary*/);
  85.             }
  86.             break;
  87.         }
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement