Pagini recente » Cod sursa (job #704613) | Cod sursa (job #1784844) | Cod sursa (job #2960224) | Cod sursa (job #2047633) | Cod sursa (job #462589)
Cod sursa(job #462589)
/**
* Text - infoarena Educational Archive
* Daniel Baluta, <[email protected]>
* Copyright (C), 2010
*/
#include <stdio.h>
int main(void)
{
char c;
int avg, ret;
FILE *f_in, *f_out;
int total_len = 0, word_no = 0, have_word = 0;
f_in = fopen("text.in", "r");
if (!f_in) {
perror("fopen");
return -1;
}
f_out = fopen("text.out", "w");
if (!f_out) {
perror("fopen");
return -1;
}
while(1) {
c = fgetc(f_in);
if (c == EOF) //end of file
break;
if ( isalpha(c) ) {
total_len++;
have_word = 1;
}
else
{
if (have_word) {
word_no++;
have_word = 0;
}
}
}
avg = total_len/word_no;
fprintf(f_out, "%d", avg);
return 0;
}