Pagini recente » Cod sursa (job #1880523) | Cod sursa (job #432599) | Cod sursa (job #2450305) | Cod sursa (job #1070441) | Cod sursa (job #1693644)
#include <stdio.h>
#include <stdbool.h>
int main() {
FILE *input, *output;
char symbol;
int words, letters, state;
bool is_letter;
input = fopen("text.in", "r");
// State:
// -> 0: reading words
// -> 1: reading delimiters
state = 0;
words = 0;
letters = 0;
while (fscanf(input, "%c", &symbol) != EOF) {
is_letter = (symbol >= 'A' && symbol <= 'Z') || (symbol >= 'a' && symbol <= 'z');
if (is_letter) {
letters += 1;
if (state == 1) {
state = 0;
words += 1;
}
} else {
if (state == 0) {
state = 1;
}
}
}
fclose(input);
int result = letters / words;
output = fopen("text.out", "w");
fprintf(output, "%d\n", result);
fclose(output);
return 0;
}