Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct worker
- {
- char* surname;
- char* name;
- char* membership;
- int age;
- char* position;
- double salary;
- };
- int main()
- {
- struct worker* uk[256];
- char buff[128];
- int age1;
- double sal1;
- int num;
- FILE* fl;
- char input_name[256];
- int i = 0;
- while (1)
- {
- printf("-----------------------------------------------------------\n");
- printf("1 - To assume the source database from the file\n");
- printf("2 - To display the current contents of the database\n");
- printf("3 - To add the worker\n");
- printf("4 - To delete the workers\n");
- printf("4 - To save the current database to the file and to show the database\n");
- printf("5 - Exit\n");
- printf("-----------------------------------------------------------\n");
- scanf("%d", &num);
- switch(num)
- {
- case 1:
- {
- printf("Please, enter the name of the file from where you want to read your database:\n");
- scanf("%s", input_name);
- if((fl = fopen(input_name, "rw")) == NULL)
- {
- printf("Can't open the file. Try again.");
- exit(1);
- }
- while (fgets(buff, 64, fl) != NULL)
- {
- uk[i] = (struct worker*) malloc(sizeof(struct worker));
- int length = strlen(buff);
- (*uk[i]).surname = (char*) malloc(length*sizeof(char) + 1);
- strcpy((*uk[i]).surname, buff);
- break;
- /* fgets(buff, 64, fl);
- length = strlen(buff);
- (*uk[i]).name = (char*) malloc(length*sizeof(char) + 1);
- strcpy((*uk[i]).name, buff);
- fgets(buff, 64, fl);
- length = strlen(buff);
- (*uk[i]).membership = (char*) malloc(length*sizeof(char) + 1);
- strcpy((*uk[i]).membership, buff);
- fgets(buff, 16, fl);
- (*uk[i]).age = atoi(buff);
- fgets(buff, 64, fl);
- length = strlen(buff);
- (*uk[i]).position = (char*) malloc(length*sizeof(char) + 1);
- strcpy((*uk[i]).position, buff);
- fgets(buff, 16, fl);
- (*uk[i]).salary = atof(buff);*/
- i++;
- }
- break;
- }
- case 2:
- {
- for (int j = 0; j < i; j++)
- {
- 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*/);
- }
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement