Cod sursa(job #2011568)

Utilizator arcoC. Nicolae arco Data 16 august 2017 16:47:56
Problema Text Scor 40
Compilator c Status done
Runda Arhiva de probleme Marime 0.96 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 || c == '\n')
			{
				if(current > 0)
				{
					words++;
				}
				break;
			}
			else
			{
				if(ispunct(c) || c == ' ' || isdigit(c))
				{
					if(current > 0)
					{
						words++;
					}
					current = 0;
				}

				if(isalpha(c) && !isdigit(c) && c != ' ')
				{
					total_len++;
					current++;
				}
			}
		}
		// printf("%lld %lld\n", total_len, words);
		fprintf(out, "%lld\n", (int64_t)(total_len / words));

		fclose(in);
		fclose(out);
	}
	else
	{
		printf("Error\n");
	}

	return 0;
}