Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAX_LEN 15
- int main(){
- int i, j, k = 0, presente = 0;
- char c;
- char **testo = NULL;
- FILE* fp = fopen("diario.txt", "r");
- if(fp == NULL){
- printf("Errore lettura file\n");
- return -1;
- }
- for(i = 0; !feof(fp); i++){
- c = fgetc(fp);
- char *buffer = malloc(20*sizeof(char));
- while((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57)){
- testo = (char **)realloc(testo, (i+1)*sizeof(char*));
- testo[k] = (char *)malloc(20*sizeof(char));
- for(j = 0; ((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57)); j++){
- buffer[j] = c;
- c = fgetc(fp);
- }
- strcpy(testo[k], buffer);
- k++;
- }
- }
- fclose(fp);
- for(int count = 1; count < MAX_LEN; count++){
- for(int index = 0; index < k; index++){
- if(strlen(testo[index]) == count)
- presente++;
- }
- if(presente != 0)
- printf("Parole lunghe %d caratteri: %d\n", count, presente);
- presente = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement