Cod sursa(job #2018029)

Utilizator arcoC. Nicolae arco Data 3 septembrie 2017 12:46:26
Problema Text Scor 40
Compilator c Status done
Runda Arhiva de probleme Marime 1.01 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 || c == '\n')
			{
				break;
			}
			else
			{
				if(isalpha(c) && c != ' ')
				{
					current_word_len++;
				}
				else
				{
					if(c == ' ' || isdigit(c) || ispunct(c))
					{
						if(current_word_len != 0)
						{
							words_count++;
						}
						total_len += current_word_len;

						current_word_len = 0;
					}
				}
			}
		}
		fprintf(out, "%u\n", total_len / words_count);

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

	return 0;
}