Cod sursa(job #2770976)

Utilizator Emmasz9Szakacs Emma Evelin Emmasz9 Data 24 august 2021 15:34:02
Problema Text Scor 0
Compilator c-32 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <stdio.h>
#include <ctype.h>
int main() {
    FILE* f = fopen("text.in.txt","r");
    if(f == NULL)
        return -1;
    char c;
    int litere = 0;
    int cuvinte = 0;
    while(fscanf(f,"%c",&c)!=EOF){
        if(isalpha(c))
            litere++;

        if(litere > 0)
            if(c ==' ' || c == ',' || c == '-')
                 cuvinte++;
    }
    printf("Numarul de litere = %d\nNumarul de cuvinte = %d\n",litere, cuvinte );
    int med = litere/cuvinte;
    FILE* f2 = fopen("text.out.txt","w");
    fprintf(f2,"%d", med);
    fclose(f);
    fclose(f2);
    return 0;
}