Advertisement
Guest User

Collaborazione Romano/Romano

a guest
Jan 23rd, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define MAX_LEN 15
  6.  
  7. int main(){
  8.     int i, j, k = 0, presente = 0;
  9.     char c;
  10.     char **testo = NULL;
  11.    
  12.     FILE* fp = fopen("diario.txt", "r");
  13.     if(fp == NULL){
  14.         printf("Errore lettura file\n");
  15.         return -1;
  16.     }
  17.    
  18.     for(i = 0; !feof(fp); i++){
  19.         c = fgetc(fp);
  20.         char *buffer = malloc(20*sizeof(char));
  21.         while((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57)){
  22.             testo = (char **)realloc(testo, (i+1)*sizeof(char*));
  23.             testo[k] = (char *)malloc(20*sizeof(char));
  24.             for(j = 0; ((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57)); j++){
  25.                 buffer[j] = c;
  26.                 c = fgetc(fp);
  27.             }
  28.             strcpy(testo[k], buffer);
  29.             k++;
  30.         }
  31.     }
  32.     fclose(fp);
  33.    
  34.     for(int count = 1; count < MAX_LEN; count++){
  35.         for(int index = 0; index < k; index++){
  36.             if(strlen(testo[index]) == count)
  37.                 presente++;
  38.         }
  39.         if(presente != 0)
  40.             printf("Parole lunghe %d caratteri: %d\n", count, presente);
  41.         presente = 0;
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement