Pagini recente » Cod sursa (job #2048571) | Cod sursa (job #640084) | Cod sursa (job #716271) | Cod sursa (job #188321) | Cod sursa (job #262805)
Cod sursa(job #262805)
#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 ';':
case '(':
case ')':
case '[':
case ']':
case '{':
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);
}