Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. //
  2. //  main.c
  3. //  lab 4 FIN
  4. //
  5. //  Created by Aleksandra Kustra on 27.03.2017.
  6. //  Copyright © 2017 Aleksandra Kustra. All rights reserved.
  7. //
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11.  
  12. struct napis {
  13.     char *str;
  14.     unsigned int len;
  15.     int iloscWstapien;
  16. };
  17.  
  18. /////////////////////
  19. void ileRazyWystapily(struct napis *tab) {
  20.     int i, j;
  21.    
  22.     for(i = 0; i < sizeof(tab); i++) {
  23.         for(j = 0; j <=i; j++) {
  24.             if(tab[i] == tab[j]) tab[i].iloscWstapien ++;
  25.         }
  26.        
  27.     }
  28. }
  29. /////////////////////////
  30. int main() {
  31.    
  32.     int wielkosc, i = 0, j;
  33.     struct napis *tab;
  34.  
  35.     FILE *napisy = fopen("napis.txt", "r");
  36.    
  37.     rewind(napisy);
  38.     //pobiera 1 linijke - ilosc napisow
  39.     fscanf(napisy, "%d", &wielkosc);
  40.     printf("%d\n", wielkosc);
  41.    
  42.    
  43.     tab = malloc(wielkosc*sizeof(struct napis));
  44.    
  45.     if(napisy) {
  46.         while(fscanf(napisy, "%d", &tab[i].len) != EOF) {
  47.            
  48.             tab[i].str = malloc((tab[i].len+1)*sizeof(char));
  49.             fscanf(napisy, " %s", tab[i].str);
  50.             i++;
  51.         }
  52.     }
  53.    
  54.    
  55.     free(tab);
  56.     free(tab[i].str);
  57.     fclose(napisy);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement