Cod sursa(job #1334390)

Utilizator alexx.cosmaCosma Cristian Alexandru alexx.cosma Data 4 februarie 2015 12:39:41
Problema Text Scor 40
Compilator c Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max 10000
int calc(char* s);

int isLet(char l);

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

    char *s = (char*)malloc(sizeof(char)*max);

    fgets(s,max,in);
    printf("%s",s);

    int c = calc(s);
    fprintf(out,"%d",c);
    return 0;
}

int calc(char* s)
{

    int nrWords=0;
    int length = 0;
    /*
        char * tok = strtok(s," `~1234567890!{@#$%^&**()-}|\":+?=><,./;'[]\"");

        while(tok!=NULL){
            length += strlen(tok);
            nrWords++;
            tok=strtok(NULL, " `~1234567890!{@#$%^&**()-}|\":+?=><,./;'[]\"");
        }
    */
    int size = strlen(s);
    int i;
    int word = 0;
    for(i=0; i<size; i++)
    {
        if(isLet(s[i]))
        {
            if(!word)
            {
                nrWords++;
            }
            word=1;
            length++;
        }
        else
        {
            word=0;
        }
    }
    return length/nrWords;

}

int isLet(char l)
{
    return l >= 65 && l<= 122;
}