Cod sursa(job #1817398)

Utilizator specialkhouseTodireanu Constantin Catalin specialkhouse Data 27 noiembrie 2016 19:05:11
Problema Text Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <stdio.h>
#include <stdlib.h>

int esteCaracter(char ch);

int main()
{
	char ch = 0;
	long int nr_caractere = 0;
	long int nr_cuvinte = 0;
	bool k = false;

	FILE *in = NULL;
	FILE *out = NULL;
	in = fopen("test.in", "r");
	out = fopen("test.out", "w");

	while ((ch = fgetc(in)) != EOF) {
		if (esteCaracter(ch) == 1) {
			nr_caractere++;
			if (!k) {
				nr_cuvinte++;
			}
			k = true;
		}
		else {
			k = false;
		}
	}

	if (nr_cuvinte == 0)
		nr_cuvinte = 1;

	fprintf(out, "%d \n", (int)(nr_caractere / nr_cuvinte));

	return 0;
}

int esteCaracter(char ch)
{
	int rez = 0;

	if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) {
		rez = 1;
	}

	return rez;
}