Pagini recente » Cod sursa (job #2327164) | Cod sursa (job #2511756) | Cod sursa (job #1442266) | Cod sursa (job #1318615) | Cod sursa (job #1448453)
#include <stdio.h>
#include <string.h>
#define MAX(a,b) ((a) < (b) ? (b) : (a))
#define IS_LETTER(c) ((c <= 'z' && c >= 'a') || (c <= 'Z' && c >= 'A'))
int main() {
FILE *in = fopen("text.in", "r"),
*out = fopen("text.out", "w");
char c, last_c = ' ';
int words = 0;
int total_len = 0;
while ((c = (char) fgetc(in)) != EOF) {
if (IS_LETTER(c)) {
total_len++;
if (!IS_LETTER(last_c))
words++;
}
last_c = c;
}
printf("words %d, total %d\n", words, total_len);
fprintf(out, "%d", total_len / MAX(1, words));
fclose(in);
fclose(out);
return 0;
}