Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdio_ext.h>
- #define max 255
- typedef struct{
- char *imie;
- char *nazwisko;
- int pesel;
- }osoba;
- typedef struct myListElement{
- osoba dane;
- struct myListElement *link;
- }Node;
- typedef struct myList{
- Node *head;
- int size;
- }myList;
- char *uzupelnienie_char(void){
- char bufor[max];
- fgets (bufor, max, stdin);
- char *tmp;
- int wymiar;
- wymiar=strlen(bufor)+1;
- tmp=malloc (wymiar * sizeof(char));
- if (!tmp){
- perror("Malloc");
- exit(2);
- }
- for (int i=0;i<wymiar;i++){
- tmp[i]=bufor[i];
- }
- return tmp;
- }
- int uzupelnienie_int(void){
- int bufor;
- char c;
- scanf("%d", &bufor);
- c = getchar();
- return bufor;
- }
- void uzupelnienie_struct(osoba *data){
- printf("Podaj imię: ");
- data -> imie = uzupelnienie_char();
- printf("Podaj nazwisko: ");
- data -> nazwisko = uzupelnienie_char();
- printf ("Podaj PESEL: ");
- data -> pesel = uzupelnienie_int();
- }
- void __init__(myList *list){
- list -> head =NULL;
- list -> size =0;
- }
- void pushFront(myList *list, osoba data){
- Node *element = (Node*) malloc (sizeof(Node));
- element -> link = list -> head;
- element -> dane = data;
- list -> head = element;
- list -> size++;
- }
- void dumpList(myList *list){
- Node *i;
- for (i=list->head;i!=NULL;i=i->link){
- printf ("Imię: %sNazwisko: %sPesel: %d\n", i->dane.imie, i->dane.nazwisko, i->dane.pesel);
- }
- printf("\n");
- }
- int main (void){
- int c=1;
- char odpowiedz;
- osoba data;
- myList list;
- __init__(&list);
- while (c==1){
- uzupelnienie_struct(&data);
- pushFront(&list, data);
- printf("Dalej Y, Przestań N\n");
- __fpurge(stdin);
- odpowiedz=getchar();
- __fpurge(stdin);
- if (odpowiedz == 'N' || odpowiedz == 'n'){
- break;
- }
- }
- dumpList(&list);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement