Pagini recente » Cod sursa (job #2460482) | Cod sursa (job #1808848) | Cod sursa (job #2098623) | Cod sursa (job #1815213) | Cod sursa (job #1693649)
#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:
// -> -1: initial
// -> 0: reading letters
// -> 1: reading delimiters
state = -1;
words = 0;
letters = 0;
while (!feof(input)) {
fscanf(input, "%c", &symbol);
is_letter = (symbol >= 'A' && symbol <= 'Z') || (symbol >= 'a' && symbol <= 'z');
if (is_letter) {
letters += 1;
if (state != 0) {
state = 0;
words += 1;
}
} else {
if (state != 1) {
state = 1;
}
}
}
fclose(input);
int result = letters / words;
output = fopen("text.out", "w");
fprintf(output, "%d\n", result);
fclose(output);
return 0;
}