Cod sursa(job #759110)

Utilizator RoxanaIstrateIstrate Roxana RoxanaIstrate Data 16 iunie 2012 18:38:53
Problema Text Scor 40
Compilator c Status done
Runda Arhiva de probleme Marime 0.68 kb
 #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;
}