Pagini recente » Cod sursa (job #1918835) | Cod sursa (job #2718171) | Cod sursa (job #1805775) | Cod sursa (job #1610697) | Cod sursa (job #2429910)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main() {
size_t text_size = 1048577;
char *text = (char *) malloc(sizeof(char) * text_size);
FILE *fp = fopen("text.in", "r");
getline(&text, &text_size, fp);
fclose(fp);
char delims[44] = " ,.;\':\"?!/[]{}<>`~@#$%^&*()-_=+\\|0123456789\0";
char *word = strtok(text, delims);
int no_of_words = 0;
int total_length = 0;
while (word) {
total_length += strlen(word);
no_of_words++;
word = strtok(NULL, delims);
}
int res = total_length / no_of_words;
fp = fopen("text.out", "w");
fprintf(fp, "%d", res);
fclose(fp);
}