Advertisement
Guest User

Untitled

a guest
May 26th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5.  
  6. typedef struct elem {
  7. char ime[30];
  8. char email[30];
  9. char akcija;
  10. int vreme;
  11. struct elem *sled;
  12. }Elem;
  13.  
  14. Elem* ucitaj(FILE *korisnici) {
  15. Elem *prvi = NULL, *pret = NULL, *novi;
  16. char name[30], mail[30];
  17.  
  18. while (fscanf(korisnici, "%s%s", name, mail) != EOF) {
  19. novi = (Elem*)malloc(sizeof(Elem));
  20. if (novi == NULL) { printf("nedostatak memorije\n"); exit(1); }
  21. novi->sled = NULL;
  22. strcpy(novi->ime, name);
  23. strcpy(novi->email, mail);
  24. novi->akcija = 'F';
  25. novi->vreme = 0;
  26. if (!prvi) prvi = novi;
  27. else pret->sled = novi;
  28. pret = novi;
  29. }
  30.  
  31.  
  32. return prvi;
  33.  
  34. }
  35.  
  36. void obrada(Elem *prvi, FILE *log) {
  37.  
  38. Elem *tek;
  39. char name[30], action;
  40. int time1;
  41.  
  42. while (fscanf(log, "%s %c %d", name, &action, &time1) != EOF) {
  43. tek = prvi;
  44.  
  45. while (tek) {
  46. if (!strcmp(tek->ime, name)) { tek->akcija = action; tek->vreme += time1; }
  47.  
  48. tek = tek->sled;
  49. }
  50.  
  51. }
  52.  
  53.  
  54. }
  55.  
  56. void obrisi(Elem *prvi) {
  57. Elem *tek;
  58.  
  59. while (prvi) {
  60. tek = prvi;
  61. prvi = prvi->sled;
  62. free(tek);
  63. }
  64.  
  65. }
  66.  
  67. int main() {
  68. FILE *log, *korisnici;
  69. log = fopen("log.txt", "r");
  70. Elem *prvi, *max, *tek;
  71.  
  72. korisnici = fopen("korisnici.txt", "r");
  73.  
  74. prvi = ucitaj(korisnici);
  75. obrada(prvi, log);
  76.  
  77. max = prvi;
  78. tek = prvi->sled;
  79.  
  80. while (tek) {
  81. if (tek->vreme > max->vreme) max = tek;
  82.  
  83. tek = tek->sled;
  84. }
  85.  
  86.  
  87. tek = prvi;
  88. while (tek) {
  89. if (tek->vreme == max->vreme) printf("%s", tek->email);
  90. tek = tek->sled;
  91. }
  92. int i;
  93. scanf("%d", &i);
  94. obrisi(prvi);
  95. fclose(log);
  96. fclose(korisnici);
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement