Advertisement
wilk_maciej

Lista osób + pesel

Jan 9th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.80 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio_ext.h>
  5. #define max 255
  6.  
  7.  
  8. typedef struct{
  9.     char *imie;
  10.     char *nazwisko;
  11.     int pesel;
  12. }osoba;
  13.  
  14. typedef struct myListElement{
  15.     osoba dane;
  16.   struct myListElement *link;
  17. }Node;
  18.  
  19. typedef struct myList{
  20.     Node *head;
  21.     int size;
  22. }myList;
  23.  
  24.  
  25. char *uzupelnienie_char(void){
  26.     char bufor[max];
  27.   fgets (bufor, max, stdin);
  28.     char *tmp;
  29.     int wymiar;
  30.     wymiar=strlen(bufor)+1;
  31.     tmp=malloc (wymiar * sizeof(char));
  32.   if (!tmp){
  33.         perror("Malloc");
  34.         exit(2);
  35.     }
  36.     for (int i=0;i<wymiar;i++){
  37.         tmp[i]=bufor[i];
  38.     }
  39.     return tmp;
  40. }
  41.  
  42. int uzupelnienie_int(void){
  43.     int bufor;
  44.     char c;
  45.     scanf("%d", &bufor);
  46.   c = getchar();
  47.   return bufor;
  48. }
  49.  
  50. void uzupelnienie_struct(osoba *data){
  51.     printf("Podaj imię: ");
  52.     data -> imie = uzupelnienie_char();
  53.     printf("Podaj nazwisko: ");
  54.   data -> nazwisko = uzupelnienie_char();
  55.   printf ("Podaj PESEL: ");
  56.   data -> pesel = uzupelnienie_int();
  57. }
  58.  
  59. void __init__(myList *list){
  60.     list -> head =NULL;
  61.     list -> size =0;
  62. }
  63.  
  64. void pushFront(myList *list, osoba data){
  65.     Node *element = (Node*) malloc (sizeof(Node));
  66.   element -> link = list -> head;
  67.   element -> dane = data;
  68.   list -> head = element;
  69.   list -> size++;
  70. }
  71.  
  72. void dumpList(myList *list){
  73.     Node *i;
  74.     for (i=list->head;i!=NULL;i=i->link){
  75.     printf ("Imię: %sNazwisko: %sPesel: %d\n", i->dane.imie, i->dane.nazwisko, i->dane.pesel);
  76.     }
  77.     printf("\n");
  78. }
  79.  
  80. int main (void){
  81.     int c=1;
  82.     char odpowiedz;
  83.     osoba data;
  84.     myList list;
  85.     __init__(&list);
  86.     while (c==1){
  87.         uzupelnienie_struct(&data);
  88.         pushFront(&list, data);
  89.         printf("Dalej Y, Przestań N\n");
  90.         __fpurge(stdin);
  91.         odpowiedz=getchar();
  92.         __fpurge(stdin);
  93.         if (odpowiedz == 'N' || odpowiedz == 'n'){
  94.             break;
  95.         }
  96.     }
  97.     dumpList(&list);
  98.     return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement