Pagini recente » Istoria paginii utilizator/zagonimathias | Cod sursa (job #2057665) | Cod sursa (job #662376) | Cod sursa (job #1592029) | Cod sursa (job #2018036)
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
typedef unsigned int uint;
int main(void)
{
// FILE *in = fopen("C:/Users/arco/Desktop/sbc/ads.txt", "r");
// FILE *out = fopen("C:/Users/arco/Desktop/sbc/out.txt", "w");
FILE *in = fopen("text.in", "r");
FILE *out = fopen("text.out", "w");
if(in != NULL && out != NULL)
{
uint total_len = 0;
uint words_count = 0;
uint current_word_len = 0;
while(1)
{
char c = getc(in);
if(c == EOF)
{
break;
}
else
{
if(isalpha(c) && c != ' ')
{
current_word_len++;
}
else
{
if(current_word_len != 0)
{
words_count++;
}
total_len += current_word_len;
current_word_len = 0;
}
}
}
if(current_word_len)
{
total_len += current_word_len;
words_count++;
}
fprintf(out, "%u\n", total_len / words_count);
fclose(in);
fclose(out);
}
else
{
printf("Error\n");
}
return 0;
}