Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5.  
  6.  
  7. typedef struct lista *Position;
  8. typedef struct lista
  9. {
  10. char *ime;
  11. char *prezime;
  12. int p2;
  13. int aisp;
  14. Position next;
  15.  
  16. }Lista;
  17. Position Alociraj(int, int);
  18. void Generiraj(Position, char *,char *,int,int);
  19. void Ispis(Position);
  20. void CitajDrugu(Position);
  21.  
  22.  
  23. void CitajDrugu(Position h)
  24. {
  25. Position neki;
  26. Position pocetak=h;
  27. char ime[20];
  28. char prezime[15];
  29. int ocj=0;
  30. int i=0;
  31.  
  32. FILE *fd;
  33. fd=fopen("asp.txt","r");
  34. if(fd==NULL)
  35. perror("greska je");
  36. else
  37. while(!feof(fd))
  38. {
  39. i=0;
  40. fscanf(fd," %s %s %d", ime,prezime, &ocj);
  41. while(h->next!=NULL)
  42. {
  43.  
  44. if((strcmp(h->next->ime,ime)==0) && (strcmp(h->next->prezime,prezime)==0))
  45. {
  46. h->next->aisp=ocj;
  47. i=1;
  48.  
  49. }
  50.  
  51. h=h->next;
  52.  
  53. }
  54. h=pocetak;
  55.  
  56. if(i==0)
  57. {
  58. h=pocetak;
  59. neki=Alociraj(strlen(ime), strlen(prezime));
  60. Generiraj(neki, ime,prezime,0,ocj);
  61. neki->next=h->next;
  62. h->next=neki;
  63. }
  64.  
  65.  
  66. }
  67. fclose(fd);
  68. }
  69.  
  70.  
  71.  
  72. void Ispis(Position h)
  73. {
  74. while(h!=NULL)
  75. {
  76. printf(" \n%s %s %d %d\n", h->ime, h->prezime, h->p2, h->aisp);
  77. h=h->next;
  78. }
  79.  
  80.  
  81. }
  82.  
  83.  
  84.  
  85. void Generiraj(Position el, char *im,char *pr,int ocj, int dr)
  86. {
  87. strcpy(el->ime,im);
  88. strcpy(el->prezime,pr);
  89. el->p2=ocj;
  90. el->aisp=dr;
  91.  
  92.  
  93. }
  94.  
  95. Position Alociraj(int duljinaim, int duljinapr)
  96. {
  97. Position el=(Position)malloc(sizeof(Lista));
  98. el->ime=(char*)malloc(duljinaim*sizeof(char));
  99. el->prezime=(char*)malloc(duljinapr*sizeof(char));
  100.  
  101.  
  102. return el;
  103. }
  104.  
  105.  
  106. void CitajIzPrve(Position h)
  107. {
  108. Position novi;
  109. char ime[30];
  110. char prezime[30];
  111. int ocjena=0;
  112. FILE *fp;
  113. fp=fopen("p2.txt","r");
  114. if(fp==NULL)
  115. perror("greska");
  116. else
  117. while(!feof(fp))
  118. {
  119.  
  120. fscanf(fp, " %s %s %d", ime, prezime, &ocjena);
  121. //printf(" %s %s %d", ime,prezime, ocjena);
  122. novi=Alociraj(strlen(ime), strlen(prezime));
  123. Generiraj(novi, ime,prezime, ocjena,0);
  124.  
  125. novi->next=h->next;
  126. h->next=novi;
  127.  
  128. }
  129.  
  130. fclose(fp);
  131. }
  132.  
  133. int main()
  134. {
  135. Lista prva;
  136. prva.next=NULL;
  137. CitajIzPrve(&prva);
  138. printf("PRVA:\n");
  139. Ispis(prva.next);
  140. printf("------------------");
  141. CitajDrugu(&prva);
  142. Ispis(prva.next);
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement