Cod sursa(job #385378)
/*
* File: main.cpp
* Author: virtualdemon
*
* Created on January 22, 2010, 5:31 PM
*/
#include <cstdio>
/*
*
*/
using namespace std;
int main()
{
char* s;
unsigned int size, nr=0, length=0, i, j;
FILE *fin=fopen( "text.in", "rt" );
fseek( fin, 0, SEEK_END ); //go to the end
size=ftell( fin ); //get the size of the file
size=sizeof(char)*size;
s=new char[ size+1 ]; //allocate memory
rewind( fin ); //go back to the beginning
fread( s, sizeof(char), size, fin ); //copy the data from the buffer to s
for( i=0; i < size; ++i )
{
if( ( s[i] >= 'a' && s[i] <= 'z' ) || ( s[i] >= 'A' && s[i] <= 'Z' ) )
{++nr;
for( j=i+1; j < size && ( ( s[j] >= 'a' && s[j] <= 'z' ) || ( s[j] >= 'A' && s[j] <= 'Z' ) ); ++j );
length+=j-i;
i=j-1;
}
}
fprintf( fopen("text.out", "wt" ), "%u", length/nr );
return 0;
}