Pagini recente » Cod sursa (job #2366735) | Cod sursa (job #2898562) | Cod sursa (job #2883366) | Cod sursa (job #1201804) | Cod sursa (job #759110)
Cod sursa(job #759110)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#define max 50
int main(){
FILE *in, *out;
char *number, *p;
int c = 0, lung = 0, i, ok = 1;
number = ( char *) malloc(max * sizeof(char));
in = fopen("text.in","r");
out = fopen("text.out","w");
if ( fgets(number,max, in ) != NULL ){
p = strtok( number, " ,.!-;:?" );
while ( p != NULL ){
ok = 1;
for ( i = 0; i < strlen(p); i++ ){
if ( !isalpha(p[i]) && !isdigit(p[i]) ){
ok = 0;
break;
}
}
if ( ok ){
c++;
lung += strlen(p);
}
p = strtok(NULL, " ,.!-;:?");
}
}
fprintf(out,"%d",lung/c);
free(number);
fclose(in);
fclose(out);
return 0;
}