Cod sursa(job #2834973)

Utilizator ciprian.morosanuCiprian Morosanu ciprian.morosanu Data 17 ianuarie 2022 22:24:24
Problema Text Scor 100
Compilator c-64 Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <stdio.h>

int main() {
    char *inFileName = "text.in";
    char *outFileName = "text.out";
    FILE *in = fopen(inFileName, "r");
    if (in == NULL) {
        printf("Cannot open %s.\n", inFileName);
        return 1;
    }
    FILE *out = fopen(outFileName, "w");
    int wordsCount = 0;
    int totalLen = 0;
    int currentWordLen = 0;

    while (1) {
        char c;
        if (fscanf(in, "%c", &c) == EOF) {
            break;
        }
        if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
            currentWordLen++;
        } else {
            if (currentWordLen != 0) {
                wordsCount++;
                totalLen += currentWordLen;
                currentWordLen = 0;
            }
        }
    }
    fprintf(out, "%d", totalLen / wordsCount);

    fclose(in);
    fclose(out);
    return 0;
}