Cod sursa(job #481121)

Utilizator CossAlbulescu Cosmina Coss Data 30 august 2010 18:08:05
Problema Text Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <stdio.h>
#include <ctype.h>
using namespace std;

char ch;
int lung, cuvinte;

int is_letter (char x)
{
    if (tolower (x) >= 'a' && tolower (x) <= 'z')
        return 1;
    return 0;
}

int main ()
{
    FILE *f = fopen ("text.in","r");
    FILE *g = fopen ("text.out","w");

    while (!feof(f))
    {
        fscanf (f,"%c", &ch);
        if (feof(f))
            break;

        if (ch == ' ')
            cuvinte ++;
        else if (is_letter (ch))
            lung ++;
    }
    cuvinte ++;

    fprintf (g, "%d\n", lung / cuvinte);

    fclose (g);
    fclose (f);
    return 0;
}