Cod sursa(job #1480494)

Utilizator raulvasileRaul Vasile raulvasile Data 2 septembrie 2015 17:51:41
Problema Text Scor 90
Compilator c Status done
Runda Arhiva de probleme Marime 0.91 kb
/* Author: Raul Vasile
 * Mail: [email protected]
 */

#include <stdio.h>
#include <string.h>

int main(int argc, char* argv[]) {
    // Declarare variable
    int c;
    int length = 0;
    int words = 0;
    int word = 0;

    // Declarare fisiere
    FILE *input, *output;

    // Deschidere fisiere
    input = fopen("text.in", "r");
    output = fopen("text.out", "w");

    // Verificare fisiere
    if (input == NULL || output == NULL) {
        printf("Error opening files");
        
        return 0;
    } else {
        do {
            c = fgetc(input);

            if ((c < 91 && c > 64) || (c < 123 && c > 96)) {
                length++;
                word = 0;
            } else {
                if (word == 0) {
                    words++;
                    word = 1;
                }
            }
        } while (c != EOF);

        fprintf(output, "%d\n", length / words);
    }

    return 0;
}