Guest User

Untitled

a guest
May 22nd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. //listy dwukierunkowe//
  4. struct Dane{
  5. char tytul[50];
  6. char autor[100];
  7. int rok;
  8. };
  9.  
  10. struct ksiazka{
  11. struct Dane dane;
  12. struct ksiazka*pop;
  13. struct ksiazka*nast;
  14. };
  15.  
  16. typedef struct ksiazka KS;
  17. typedef KS*WSK;
  18.  
  19. void dodaj(struct Dane d, WSK*pocz){
  20. WSK nowy, ost;
  21. nowy=(WSK)malloc(sizeof(KS));
  22. nowy->dane.rok=d.rok;
  23. strcpy(nowy->dane.tytul,d.tytul);
  24. strcpy(nowy->dane.autor,d.autor);
  25.  
  26. if(*pocz==NULL){
  27. (*pocz)=nowy;
  28. nowy->pop=NULL;
  29. nowy->nast=NULL;
  30. return;
  31. }
  32.  
  33. ost=(*pocz);
  34. while(ost->nast!=NULL);
  35. ost=ost->nast;
  36. ost->nast=nowy;
  37. nowy->nast=NULL;
  38. nowy->pop=ost;
  39. }
  40.  
  41. void wypisz(WSK pocz){
  42. WSK pom=pocz;
  43. int i=1;
  44. while(pom!=NULL){
  45. printf("%d.%s %s %d ", i++,pom->dane.tytul,pom->dane.autor,pom->dane.rok);
  46. pom=pom->nast;
  47. }
  48. }
  49. void czysc(WSK*pocz){
  50. WSK pom;
  51. if((*pocz)!=NULL)
  52. while((*pocz)->nast!=NULL)
  53. (*pocz)=(*pocz)*nast;
  54. free((*pocz)->pop);
  55. }
  56. free(*pocz);
  57.  
  58. int main()
  59. {
  60. WSK pocz=NULL;
  61. FILE*f;
  62.  
  63. f=fopen("...", "rt");
  64. if(f==NULL)...
  65.  
  66. while(fscanf(f,"%s\n%s\n%d", d.tytul,d.autor,&(d.rok))==3){
  67.  
  68. return 0;
  69. }
  70. dodaj(d,&pocz);
  71. }
  72. fclose(f);
  73. wypisz(pocz);
  74. printf("Podaj ksiazke, ktora chcesz znalezc");
  75. printf("Tytul: ");
  76. scanf("%s", d.tytul.);
  77.  
  78. printf("Autor: ");
  79. scanf("%s", d.autor);
  80. printf("Rok: ", d.rok);
  81. scanf("%s", &(d.rok));
  82.  
  83. if(czIstnieje(d, pocz))==1
  84. printf("Istnieje");
  85. else
  86. printf("Brak");
  87. czysc(&pocz);
  88.  
  89. return 0;
  90. }
  91. int czyIstnieje(struct Dane d, WSK pocz){
  92.  
  93. while(pocz!=NULL){
  94. if(strcmp(d.tytul, pocz->dane.tytul)
  95. strcmp(d.autor, pocz->dane.autor)&&d.rok==pocz->dane.rok)
  96.  
  97. return 1;
  98. }
  99.  
  100.  
  101. pocz=pocz->nast;
  102.  
  103. }
  104.  
  105. }
Add Comment
Please, Sign In to add comment