Pagini recente » Cod sursa (job #1029249) | Cod sursa (job #1245583) | Cod sursa (job #1361213) | Cod sursa (job #2161940) | Cod sursa (job #2011576)
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <stdint.h>
#include <ctype.h>
typedef unsigned int uint;
int main(void)
{
FILE *in = fopen("text.in", "r");
FILE *out = fopen("text.in", "w");
if(in != NULL && out != NULL)
{
int64_t total_len = 0;
int64_t words = 0;
int64_t current = 0;
char c = 'a';
while(1)
{
c = getc(in);
if(c == EOF || c == -1)
{
if(current > 0)
{
words++;
}
break;
}
else
{
if(strchr("1234567890.?!@#$%^&*()[]\":;'-=+_ ", c) != NULL)
{
if(current > 0)
{
words++;
current = 0;
}
}
else
{
if(isalpha(c))
{
total_len++;
current++;
}
}
}
}
printf("%lld %lld\n", total_len, words);
fprintf(out, "%lld\n", (int64_t)(total_len / words));
fclose(in);
fclose(out);
}
else
{
printf("Error\n");
}
return 0;
}