Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. int load_clusters(char *filename, struct cluster_t **arr)
  2. {
  3. assert(arr != NULL);
  4.  
  5. // TODO
  6.  
  7. //nacitanie suboru a kontrola nacitaniashallo
  8. FILE *fp = fopen(filename, "r");
  9. if ( fp == NULL)
  10. {
  11. fprintf(stderr, "Nepodarilo sa nacitat subor\n");
  12. return -1;
  13. }
  14.  
  15. // nacitanie count=N
  16. const int N;
  17. char string[20];
  18. fgets(string, 20, fp);
  19. sscanf(string, "count=%d", &N);
  20.  
  21. // alokovanie miesta pre vsetky zhluky
  22. *arr = malloc(sizeof(struct cluster_t) * N);
  23.  
  24. // loop na nacitanie ostatnych objektov
  25. int i;
  26. for ( i = 0; i < N; i++ )
  27. {
  28. fgets(string, 20, fp);
  29. struct obj_t obj;
  30. sscanf(string, "%d %f %f", &obj.id, &obj.x, &obj.y);
  31. init_cluster(c, 1);
  32. append_cluster(c, obj);
  33.  
  34. // zaradenie zhluku do bola zhlukov
  35. *arr->c[i] = c;
  36. }
  37. }
  38.  
  39.  
  40.  
  41.  
  42.  
  43. void init_cluster(struct cluster_t *c, int cap)
  44. {
  45. assert(c != NULL);
  46. assert(cap >= 0);
  47.  
  48. // TODO
  49.  
  50. // pointer na NULL u pole objektu
  51. if ( c->obj == NULL)
  52. {
  53. c->capacity = 0;
  54. fprintf(stderr, "Nealokovana pamat\n");
  55. }
  56.  
  57. // declaracia capacity zhluku a velkosti zhluku
  58. c->capacity = cap;
  59. c->size = 0;
  60.  
  61. // alokovanie pamate pre zhluk
  62. c->obj = malloc(sizeof(struct obj_t) * cap);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement