Pp9

tia

Pp9
Dec 16th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct lista
  6. {
  7.     char napis[20];
  8.     struct lista *n;
  9. } element;
  10.  
  11. void wpisz(element **pocz);
  12. void czyt_l(element *pocz);
  13.  
  14. int main()
  15. {
  16.  
  17.     element *slowa;
  18.     //slowa=malloc(sizeof(element));
  19.     wpisz (&slowa);
  20.     czyt_l(slowa);
  21.  
  22.  
  23.     return 0;
  24. }
  25.  
  26. void wpisz(element **slowo)
  27. {
  28.     int d;
  29.     char c, w[20];
  30.     element *pom=*slowo;
  31.  
  32.     printf("\ndaj cos oprocz 0!");
  33.     scanf("%d", &d);
  34.     while(d)
  35.     {
  36.  
  37.         printf("\nPodaj napis: ");
  38.         scanf("%s", pom->napis);
  39.  
  40.         printf("\ndaj cos oprocz 0!");
  41.         scanf("%d", &d);
  42.  
  43.         if(d==0)
  44.         {
  45.             pom->n=NULL;
  46.             return;
  47.         }
  48.  
  49.         pom->n=malloc(sizeof(element));
  50.         pom=pom->n;
  51.     }
  52.     *slowo=NULL;
  53. }
  54.  
  55. void czyt_l(element *slowo)
  56. {
  57.     int i;
  58.     element *c;
  59.     c=slowo;
  60.     printf("\n");
  61.     if(c==NULL) printf("\nLista pusta!");
  62.     for(i=0; c!=NULL; i++,c=c->n) printf("%d slowo w liscie: %s\n",i+1, c->napis);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment