Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int load_clusters(char *filename, struct cluster_t **arr)
- {
- assert(arr != NULL);
- // TODO
- FILE *soubor;
- int pocet = 0;
- int id;
- float x,y;
- soubor = fopen(filename, "r");
- fscanf(soubor, "count=%d",&pocet);
- int i = 0;
- *arr = malloc(sizeof(struct cluster_t)*pocet); // alokuji si pole clusterù na pozadovanou velikosr
- for ( i = 0;i<pocet;i++)
- {
- init_cluster(&arr[0][i],50); //inicializu si [i]tý cluster o kapacitì max 1.
- fscanf(soubor, "%d %f %f", &id, &x, &y); // naètu id x y
- 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
- objekt->id=id; // priradim do pomocneho objektu ID
- objekt->x=x; // priradim do pomocneho objektu X
- objekt->y=y; // priradim do pomocneho objektu Y
- append_cluster(&arr[0][i],*objekt);
- }
- return i;
- }
- /*
- Tisk pole shluku. Parametr 'carr' je ukazatel na prvni polozku (shluk).
- Tiskne se prvnich 'narr' shluku.
- */
- void print_clusters(struct cluster_t *carr, int narr)
- {
- printf("Clusters:\n");
- for (int i = 0; i < narr; i++)
- {
- printf("cluster %d: ", i);
- print_cluster(&carr[i]);
- }
- }
- int main(int argc, char *argv[])
- {
- struct cluster_t *clusters;
- // TODO
- load_clusters("idk.txt",&clusters);
- print_clusters(&clusters[0],20);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement