Cod sursa(job #1485831)

Utilizator AndreiIstetulAndrei Andrei AndreiIstetul Data 13 septembrie 2015 04:55:29
Problema Text Scor 20
Compilator c Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <stdio.h>
//#include <stdlib.h>
#include <string.h>

FILE *in, *out;
char str[1030], *ptr;
unsigned words, len;

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

    fgets(str, 1024, in);

    ptr = strtok(str, " !?-,.");
    while (ptr)
    {
        len += strlen(ptr);
        ++words;

        ptr = strtok(NULL, " !?-,.");
    }

    fprintf(out, "%u", (unsigned)((float)len / (float)words));

    fclose(in);
    fclose(out);

    return 0;
}