Pagini recente » Cod sursa (job #334562) | Cod sursa (job #377757) | Cod sursa (job #192231) | Profil CozmaCatalin | Cod sursa (job #203011)
Cod sursa(job #203011)
#include <stdio.h>
#include <ctype.h>
enum state{
IN_WORD,
OUT_WORD
};
int main(){
FILE* in, *out;
enum state crt_state = OUT_WORD;
char crt_symbol;
int no_words = 0, no_letters = 0;
in = fopen("text.in", "r");
if(!in){
fprintf(stderr,"Unable to open input file\n");
return 1;
}
out = fopen("text.out", "w");
if(!out){
fprintf(stderr,"Unable to open output file\n");
return 1;
}
while(1){
crt_symbol = fgetc(in);
if(EOF == crt_symbol)
break;
if(crt_state == OUT_WORD){
if(isalpha(crt_symbol)){
no_words++;
no_letters++;
crt_state = IN_WORD;
}
}
else
{
if(isalpha(crt_symbol))
no_letters++;
else
crt_state = OUT_WORD;
}
}
if(0 == no_letters)
fprintf(out,"0");
else
fprintf(out,"%d",no_words/no_letters);
fclose(in);
fclose(out);
return 0;
}