Pagini recente » Cod sursa (job #1201061) | Cod sursa (job #1372894) | Cod sursa (job #2175606) | Cod sursa (job #1042688) | Cod sursa (job #385369)
Cod sursa(job #385369)
/*
* File: main.cpp
* Author: virtualdemon
*
* Created on January 22, 2010, 5:31 PM
*/
#include <cstdio>
/*
*
*/
using namespace std;
int main()
{
char* s, *p, *q;
unsigned int size, nr=0, length=0;
FILE *fin=fopen( "text.in", "rt" );
fseek( fin, 0, SEEK_END ); //go to the end
size=ftell( fin ); //get the size of the file
s=new char[ sizeof(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( p=s; *p; )
{
if( ( *p >= 'a' && *p <= 'z' ) || ( *p >= 'A' && *p <= 'Z' ) )
{++nr;
for( q=p ; *p && ( ( *p >= 'a' && *p <= 'z' ) || ( *p >= 'A' && *p <= 'Z' ) ); ++p );
length+=p-q;
}
else ++p;
}
fprintf( fopen("text.out", "wt" ), "%u", length/nr );
return 0;
}