Pagini recente » Cod sursa (job #2485775) | Cod sursa (job #2643543) | Cod sursa (job #1290771) | Cod sursa (job #1058103) | Cod sursa (job #981563)
Cod sursa(job #981563)
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE* in = fopen("text.in", "r");
FILE* out = fopen("text.out", "w");
if (in != NULL && out != NULL) {
char chr;
int newWord = 0;
int wordsLength = 0;
int wordsCount = 0;
while ((chr = fgetc(in)) != EOF) {
//printf("%c %d, ", chr, chr);
if((chr >= 65 && chr <= 90) || (chr >= 97 && chr <= 122)) {
wordsLength++;
newWord = 1;
} else {
if (newWord) {
wordsCount++;
newWord = 0;
}
}
}
//printf("\n\n%d words length", wordsLength);
//printf("\n\n%d words count", wordsCount);
//printf("\n\n%d medium words length", wordsLength / wordsCount);
fprintf(out, "%d", wordsLength / wordsCount);
}
if (in != NULL) {
fclose(in);
}
if (out != NULL) {
fclose(out);
}
return 0;
}