Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct lista_okregow{
- char figura;
- int wsp_x, wsp_y, r;
- struct lista_okregow *next;
- }lista_o;
- typedef struct lista_prostokatow{
- char figura;
- int wsp_x, wsp_y, wsp2_x, wsp2_y;
- struct lista_prostokatow *next;
- }lista_p;
- void sortowanie (char* nazwa_pliku, lista_o **wierzcholek_o, lista_p **wierzcholek_p)
- {
- lista_o *nowy1;
- lista_p *nowy2;
- FILE * plik;
- char figura, wiersz[64], pom;
- int wsp_x, wsp_y, r, wsp2_x, wsp2_y;
- if((plik = fopen(nazwa_pliku,"r"))==NULL)
- {
- printf("plik nie zostal otwarty");
- return NULL;
- }
- while((fgets(wiersz, sizeof(wiersz), plik)))
- {
- pom = wiersz[0];
- if(pom == 'o' || pom == 'O')
- {
- printf("%c\n",pom );
- nowy1 = malloc(sizeof(lista_o));
- sscanf(wiersz, "%c %d %d %d", &figura, &wsp_x, &wsp_y, &r);
- nowy1 -> figura = figura;
- nowy1 -> wsp_x = wsp_x;
- nowy1 -> wsp_y = wsp_y;
- nowy1 -> r = r;
- nowy1 -> next = *wierzcholek_o;
- *wierzcholek_o = nowy1;
- }
- else if(pom == 'p' || pom == 'P')
- {
- printf("%c\n",pom );
- nowy2 = malloc(sizeof(lista_p));
- sscanf(wiersz, "%c %d %d %d %d", &figura, &wsp_x, &wsp_y, &wsp2_x, &wsp2_y);
- nowy2 -> figura = figura;
- nowy2 -> wsp_x = wsp_x;
- nowy2 -> wsp_y = wsp_y;
- nowy2 -> wsp2_x = wsp2_x;
- nowy2 -> wsp2_y = wsp2_y;
- nowy2 -> next = *wierzcholek_p;
- *wierzcholek_p = nowy2;
- }
- }
- fclose(plik);
- }
- void wyswietlanie_o(lista_o* nazwa_listy)
- {
- lista_o *pomoc;
- pomoc = nazwa_listy;
- while(pomoc->next != NULL) {
- printf("%c %d %d %d\n",pomoc->figura, pomoc->wsp_x, pomoc->wsp_y, pomoc->r);
- pomoc = pomoc->next;
- }
- }
- void wyswietlanie_p(lista_p* nazwa_listy)
- {
- lista_p *pomoc;
- pomoc = nazwa_listy;
- while(pomoc->next != NULL) {
- printf("%c %d %d %d %d\n",pomoc->figura, pomoc->wsp_x, pomoc->wsp_y, pomoc->wsp2_x, pomoc->wsp2_y);
- pomoc = pomoc->next;
- }
- }
- int pop_o(lista_o** adres_listy) {
- lista_o** head = (lista_o**)adres_listy;
- lista_o* new_head = (*head)->next;
- free(*head);
- if(new_head != NULL) *head = new_head;
- else *head = NULL;
- return 0;
- }
- int pop_p(lista_p** adres_listy) {
- lista_p** head = (lista_p**)adres_listy;
- lista_p* new_head = (*head)->next;
- free(*head);
- if(new_head != NULL) *head = new_head;
- else *head = NULL;
- return 0;
- }
- int main()
- {
- lista_o *wierzcholek_o = malloc(sizeof(lista_o)) , *pomoc_o;
- lista_p *wierzcholek_p = malloc(sizeof(lista_p)) , *pomoc_p;
- wierzcholek_o->next = NULL;
- wierzcholek_p->next = NULL;
- sortowanie("figury.txt", &wierzcholek_o, &wierzcholek_p);
- /*printf("%p\n", *wierzcholek_o);
- printf("%p\n", *wierzcholek_p);
- pomoc_o = wierzcholek_o;
- pomoc_p = wierzcholek_p;*/
- wyswietlanie_o(wierzcholek_o);
- wyswietlanie_p(wierzcholek_p);
- pop_o(wierzcholek_o);
- wyswietlanie_o(wierzcholek_o);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement