Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. int load_clusters(char *filename, struct cluster_t **arr)
  2. {
  3. assert(arr != NULL);
  4.  
  5. // TODO
  6. FILE *soubor;
  7.  
  8. int pocet = 0;
  9. int id;
  10. float x,y;
  11.  
  12. soubor = fopen(filename, "r");
  13.  
  14. fscanf(soubor, "count=%d",&pocet);
  15. int i = 0;
  16. *arr = malloc(sizeof(struct cluster_t)*pocet); // alokuji si pole clusterù na pozadovanou velikosr
  17.  
  18. for ( i = 0;i<pocet;i++)
  19. {
  20. init_cluster(&arr[0][i],50); //inicializu si [i]tý cluster o kapacitì max 1.
  21.  
  22. fscanf(soubor, "%d %f %f", &id, &x, &y); // naètu id x y
  23.  
  24. struct obj_t *objekt = malloc(sizeof(struct obj_t)); //vytvoøím si pomocný objekt obj_t a ulozim do nej ukazatele na misto v pameti, kde je na nej misto
  25. objekt->id=id; // priradim do pomocneho objektu ID
  26. objekt->x=x; // priradim do pomocneho objektu X
  27. objekt->y=y; // priradim do pomocneho objektu Y
  28.  
  29. append_cluster(&arr[0][i],*objekt);
  30. }
  31. return i;
  32. }
  33. /*
  34. Tisk pole shluku. Parametr 'carr' je ukazatel na prvni polozku (shluk).
  35. Tiskne se prvnich 'narr' shluku.
  36. */
  37. void print_clusters(struct cluster_t *carr, int narr)
  38. {
  39. printf("Clusters:\n");
  40. for (int i = 0; i < narr; i++)
  41. {
  42. printf("cluster %d: ", i);
  43. print_cluster(&carr[i]);
  44. }
  45. }
  46.  
  47. int main(int argc, char *argv[])
  48. {
  49. struct cluster_t *clusters;
  50.  
  51.  
  52. // TODO
  53. load_clusters("idk.txt",&clusters);
  54. print_clusters(&clusters[0],20);
  55.  
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement