Pagini recente » Cod sursa (job #1631730) | Cod sursa (job #1629184) | Cod sursa (job #2451804) | Cod sursa (job #2664730) | Cod sursa (job #2834973)
#include <stdio.h>
int main() {
char *inFileName = "text.in";
char *outFileName = "text.out";
FILE *in = fopen(inFileName, "r");
if (in == NULL) {
printf("Cannot open %s.\n", inFileName);
return 1;
}
FILE *out = fopen(outFileName, "w");
int wordsCount = 0;
int totalLen = 0;
int currentWordLen = 0;
while (1) {
char c;
if (fscanf(in, "%c", &c) == EOF) {
break;
}
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
currentWordLen++;
} else {
if (currentWordLen != 0) {
wordsCount++;
totalLen += currentWordLen;
currentWordLen = 0;
}
}
}
fprintf(out, "%d", totalLen / wordsCount);
fclose(in);
fclose(out);
return 0;
}