Cod sursa(job #1109284)

Utilizator dorinmoldovanMoldovan Dorin dorinmoldovan Data 16 februarie 2014 22:11:53
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <stdio.h>

int main()
{
	FILE* fp;
	char c;
	char d = 0;
	fp = fopen("text.in", "r");

	int numberOfWords = 0;
	int totalLength = 0;

	while((c = fgetc(fp)) != EOF)
	{
		if(c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') 
		{
			totalLength++;
			if(!(d >= 'a' && d <= 'z' || d >= 'A' && d <= 'Z'))
				numberOfWords++;
		} 
		d = c;
	}

	fclose(fp);

	int result = totalLength / numberOfWords;

	FILE* fq;
	fq = fopen("text.out", "w");
	fprintf(fq, "%d", result);
	fclose(fq);

	return 0;
}