Cod sursa(job #1109282)

Utilizator dorinmoldovanMoldovan Dorin dorinmoldovan Data 16 februarie 2014 22:10:26
Problema Text Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <stdio.h>

void 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);
}