Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #define CRT_SECURE_NO_WARNINGS
- struct kontakt
- {
- char *imie;
- char *nazwisko;
- char *grupa;
- char *numer;
- };
- struct lista
- {
- struct lista *poprzedni;
- struct lista *nastepny;
- struct kontakt dane;
- }*top;
- struct lista * wczytaj(FILE *plik)
- {
- char buff[100];
- struct lista *ptr;
- ptr= malloc(sizeof(struct lista));
- fscanf(plik, "%[^;];", buff);
- ptr->dane.imie=(char*)malloc(sizeof(char)* (strlen(buff) + 1));
- strcpy (ptr->dane.imie ,buff);
- fscanf(plik, "%[^;];", buff);
- ptr->dane.nazwisko=(char*)malloc(sizeof(char)* (strlen(buff) + 1));
- strcpy (ptr->dane.nazwisko ,buff);
- fscanf(plik, "%[^;];", buff);
- ptr->dane.grupa=(char*)malloc(sizeof(char)* (strlen(buff) + 1));
- strcpy (ptr->dane.grupa ,buff);
- fscanf(plik, "%[^;];\n", buff);
- ptr->dane.numer=(char*)malloc(sizeof(char)* (strlen(buff) + 1));
- strcpy (ptr->dane.numer ,buff);
- printf("%s; %s; %s; %s;\n", ptr->dane.imie, ptr->dane.nazwisko, ptr->dane.grupa, ptr->dane.numer);
- return ptr;
- }
- struct lista *tworz()
- {
- struct lista *ptrp, *ptr;
- FILE *f;
- char *c;
- ptr= malloc(sizeof(struct lista));
- ptrp= malloc(sizeof(struct lista));
- f= fopen("lista.txt", "r");
- while(c[0]!=EOF)
- {
- ptr = wczytaj(f);
- c[0]=getc(f);
- ptr->dane.imie=strcpy(c, ptr->dane.imie);
- if(ptr->poprzedni!=NULL)
- {
- ptr->poprzedni->nastepny = ptr;
- }
- ptr->poprzedni= ptrp;
- ptrp= ptr;
- }
- fclose(f);
- return ptr;
- }
- void printlista(struct lista *glowa)
- {
- while(glowa->poprzedni!=NULL)
- {
- printf("%s; %s; %s; %s;\n", glowa->dane.imie, glowa->dane.nazwisko, glowa->dane.grupa, glowa->dane.numer);
- glowa=glowa->poprzedni;
- }
- }
- int main()
- {
- top= tworz();
- printlista(top);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement