Cod sursa(job #981563)

Utilizator Xavierpana emil Xavier Data 7 august 2013 15:37:28
Problema Text Scor 100
Compilator c Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <stdio.h>
#include <stdlib.h>

int main()
{
    FILE* in = fopen("text.in", "r");
    FILE* out = fopen("text.out", "w");
    
    if (in != NULL && out != NULL) {
        
        char chr;
        int newWord = 0;
        int wordsLength = 0;
        int wordsCount = 0;
        
        while ((chr = fgetc(in)) != EOF) {
            
            //printf("%c %d, ", chr, chr);
            
            if((chr >= 65 && chr <= 90) || (chr >= 97 && chr <= 122)) {
                wordsLength++;
                newWord = 1;
            } else {
                if (newWord) {
                    wordsCount++;
                    
                    newWord = 0;
                }
            }
        }
        
        //printf("\n\n%d words length", wordsLength);
        //printf("\n\n%d words count", wordsCount);
        //printf("\n\n%d medium words length", wordsLength / wordsCount);
        
        fprintf(out, "%d", wordsLength / wordsCount);
    }
    
    if (in != NULL) {
        fclose(in);
    }
    
    if (out != NULL) {
        fclose(out);
    }
    
    return 0;
}