Cod sursa(job #2018036)

Utilizator arcoC. Nicolae arco Data 3 septembrie 2017 12:52:10
Problema Text Scor 100
Compilator c Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>

typedef unsigned int uint;

int main(void)
{
	// FILE *in = fopen("C:/Users/arco/Desktop/sbc/ads.txt", "r");
	// FILE *out = fopen("C:/Users/arco/Desktop/sbc/out.txt", "w");
	FILE *in = fopen("text.in", "r");
	FILE *out = fopen("text.out", "w");
	if(in != NULL && out != NULL)
	{
		uint total_len = 0;
		uint words_count = 0;

		uint current_word_len = 0;
		while(1)
		{
			char c = getc(in);
			if(c == EOF)
			{
				break;
			}
			else
			{
				if(isalpha(c) && c != ' ')
				{
					current_word_len++;
				}
				else
				{
					if(current_word_len != 0)
					{
						words_count++;
					}
					total_len += current_word_len;

					current_word_len = 0;
				}
			}
		}
		if(current_word_len)
		{
			total_len += current_word_len;
			words_count++;
		}

		fprintf(out, "%u\n", total_len / words_count);

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

	return 0;
}