G2A Many GEOs
SHARE
TWEET

Untitled

a guest Apr 8th, 2020 146 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdlib.h>
  2. #include<stdio.h>
  3.  
  4. #define COUPLES ((size_t) 2)
  5. #define SIZE ((size_t) 20)
  6.  
  7. typedef enum Gender {
  8.     Female = 0,
  9.     Male = 1
  10. } eGender;
  11.  
  12. typedef struct Human {
  13.     char name[SIZE];
  14.     unsigned char age;
  15.     eGender gender;
  16.     struct Human* partner;
  17. } t_Human;
  18.  
  19. int main()
  20. {
  21.     FILE* fp = fopen("list.txt", "r");
  22.  
  23.     if (fp == NULL) {
  24.         (void)printf("File not found!\n");
  25.         exit(0);
  26.     }
  27.  
  28.     size_t i;
  29.  
  30.     t_Human people[COUPLES] = {0};
  31.  
  32.     for (i = 0; i < COUPLES; ++i)
  33.         people[i].partner = (t_Human*) malloc(sizeof(t_Human));
  34.  
  35.     for (i = 0; i < COUPLES; ++i) {
  36.         (void)fscanf(fp, "%s | %d | %d\n", people[i].name, &people[i].age, &people[i].gender);
  37.         (void)fscanf(fp, "%s | %d | %d\n", people[i].partner->name, &people[i].partner->age, &people[i].partner->gender);
  38.     }
  39.  
  40.     fclose(fp);
  41.  
  42.     for (i = 0; i < COUPLES; ++i)
  43.         (void)printf("Name %s, age %d and gender value %d with fellow named %s, age %d and gender value %d.\n", people[i].name, people[i].age, people[i].gender, people[i].partner->name, people[i].partner->age, people[i].partner->gender);
  44.  
  45.     for (i = 0; i < COUPLES; ++i)
  46.         free(people[i].partner);
  47.  
  48.     return 0;
  49. }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top