Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h> //EXIT_SUCCESS, calloc
  4.  
  5. struct A
  6. {
  7. char *name;
  8. int id;
  9. };
  10.  
  11. struct B
  12. {
  13. char *buildingName;
  14. struct a *ptra;
  15. };
  16.  
  17.  
  18. int main()
  19. {
  20.  
  21. int employe = 1;
  22. int NrOfBuildinTemplates = 3;
  23.  
  24. struct A *humans;
  25. struct B *buildings;
  26.  
  27. humans = calloc(employe, sizeof(struct A));
  28. buildings = calloc(NrOfBuildinTemplates, sizeof(struct B));
  29.  
  30. buildings[0].buildingName = strdup("Building A");
  31. buildings[1].buildingName = strdup("Building B");
  32. buildings[2].buildingName = strdup("Building C");
  33.  
  34.  
  35. int count = 100, n = 0;
  36. for (size_t i = 3; i < count; i++)
  37. {
  38. buildings = realloc(buildings, i+1);
  39. buildings[i].buildingName = strdup("Building XYZ");
  40. buildings[i].ptra = (*buildings->ptra) calloc(1, buildings->ptra);
  41. buildings[i].ptra = &(humans[n]);
  42. buildings[i].ptra = strdup("NameXYZ");
  43. humans = realloc(humans, n+1);
  44. n++;
  45. }
  46.  
  47.  
  48. for (size_t i = 3; i < count; i++)
  49. {
  50. printf("%s -> %sn", buildings[i].buildingName, buildings[i].ptra->name);
  51. n++;
  52. }
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement