Cod sursa(job #2011581)

Utilizator arcoC. Nicolae arco Data 16 august 2017 17:02:07
Problema Text Scor 70
Compilator c Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <stdint.h>
#include <ctype.h>
 
typedef unsigned int uint;
 
int main(void)
{
    FILE *in = fopen("text.in", "r");
	FILE *out = fopen("text.out", "w");
    if(in != NULL && out != NULL)
    {
        int64_t total_len = 0;
        int64_t words = 0;
        int64_t current = 0;
 
        char c = 'a';
        while(1)
        {
            c = getc(in);
            if(c == EOF || c == -1)
            {
                break;
            }
            else
            {
                if(strchr("1234567890.?!@#$\\/,^&*()[]%%<>{}\":;'-=+_	 ", c) != NULL)
                {
                    if(current > 0)
                    {
                        words++;
                        current = 0;
                    }
                }
 				else
 				{
	                if(isalpha(c))
	                {
	                    total_len++;
	                    current++;
	                }
	            }
            }
        }
        if(current > 0)
        {
        	words++;
        }
        fprintf(out, "%lld\n", (int64_t)(total_len / words));
 
        fclose(in);
        fclose(out);
    }
    else
    {
        printf("Error\n");
    }
 
    return 0;
}