Pagini recente » Cod sursa (job #1068093) | Cod sursa (job #1699666) | Cod sursa (job #356380) | Cod sursa (job #2915065) | Cod sursa (job #385345)
Cod sursa(job #385345)
#include <cstring>
#include <cstdio>
/*
*
*/
using namespace std;
int main()
{char *s;
FILE *fin=fopen( "text.in", "rt" );
fseek( fin, 0, SEEK_END ); //go to the end
unsigned int size=ftell( fin ), nr=0, length=0, n, i, j; //get the size of the file
rewind( fin ); //go back to the first line
n=sizeof(char)*size;
s=new char[ n ]; //alloc size
fread( s, sizeof(char), size, fin ); //copy the data from the buffer to s
for( i=0, n=strlen(s); i < n; i=j )
{j=i+1;
if( ( s[i] >= 'a' && s[i] <= 'z' ) || ( s[i] >= 'A' && s[i] <= 'Z' ) )
{++nr;
for( ; j < n && ( ( s[j] >= 'a' && s[j] <= 'z' ) || ( s[j] >= 'A' && s[j] <= 'Z' ) ); ++j );
length+=j-i;
}
}
if( nr )
fprintf( fopen("text.out", "wt"), "%u", length/nr );
return 0;
}