Pagini recente » Cod sursa (job #2754895) | Cod sursa (job #440025) | Cod sursa (job #1618157) | Cod sursa (job #981044) | Cod sursa (job #262803)
Cod sursa(job #262803)
#include <stdio.h>
#include <string.h>
int main()
{
FILE *in = fopen("text.in", "r");
FILE *out = fopen("text.out", "w");
long nbChars = 0;
long nbWords = 0;
char c;
char oldCh = ' ';
bool lastChIsLetter = false;
while((c=getc(in))!=EOF)
{
switch (c)
{
case ' ':
case ',':
case '!':
case '?':
case '.':
case '\n':
case '-':
case '+':
case '/':
case ':':
case ';':
lastChIsLetter = false;
break;
default:
nbChars ++;
if (!lastChIsLetter)
nbWords ++;
lastChIsLetter = true;
break;
}
oldCh = c;
}
fprintf(out, "%ld", nbChars/nbWords);
fclose(in);
fclose(out);
}