Pagini recente » Cod sursa (job #2132799) | Cod sursa (job #1397157) | Statistici Alondra (agpagpagpagpa) | Cod sursa (job #1878742) | Cod sursa (job #3301462)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
using namespace std;
int main()
{
FILE *file_in = fopen("text.in", "r");
FILE *file_out = fopen("text.out", "w");
fseek(file_in, 0, SEEK_END);
long sz = ftell(file_in);
fseek(file_in, 0, SEEK_SET);
char *buf = (char *)malloc(sz + 1);
fread(buf, 1, sz, file_in);
buf[sz] = '\0';
for (long i = 0; i < sz; i++) {
if (!isalpha((unsigned char)buf[i])) {
buf[i] = ' ';
}
}
int l = 0, nr = 0;
char *s = strtok(buf, " ");
while (s) {
l += strlen(s);
nr++;
s = strtok(NULL, " ");
}
fprintf(file_out, "%d\n", l / nr);
fclose(file_in);
fclose(file_out);
}