Cod sursa(job #2020327)

Utilizator speedylawl1Cota Calin speedylawl1 Data 9 septembrie 2017 21:25:22
Problema Text Scor 100
Compilator c Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
	char a[1034];
	int total, cuvinte;
	int read;
	FILE *f, *g;
	int first = 0;
	total = 0;
	cuvinte = 0;

	f = fopen("text.in", "r");
	g = fopen("text.out", "w");
	if (NULL == f)
	{
		return 0;
	}
	if (NULL == g)
	{
		return 0;
	}

	do 
	{
		read = fread(a, sizeof(char), 1024, f);
		a[read] = 0;
		for (int i = 0; i < (int)strlen(a); i++)
		{
			a[i] = a[i] | 0x20;
			if (a[i] >= 'a' && a[i] <= 'z')
			{
				total++;
				first = 1;
			}
			else
			{
				if (first)
				{
					cuvinte++;
					first = 0;
				}
			}
		}
	} while (read > 0);

	if (cuvinte == 0)
		return 0;
	fprintf(g, "%d", (int)total / cuvinte);

	fclose(f);
	fclose(g);

	return 0;
}