Pagini recente » Cod sursa (job #3203025) | Cod sursa (job #1504221) | Monitorul de evaluare | Cod sursa (job #1290971) | Cod sursa (job #385344)
Cod sursa(job #385344)
#include <cstring>
#include <cstdio>
/*
*
*/
using namespace std;
int main()
{char *s, *p, sep[]=" 1234567890~`!@#$%^&*()_-+={[]}|\\:;\"\',<>.?/";
FILE *fin=fopen( "text.in", "rt" );
fseek( fin, 0, SEEK_END ); //go to the end
unsigned int size=ftell( fin ), nr=0, length=0; //get the size of the file
rewind( fin ); //go back to the first line
s=new char[ sizeof(char)*size ]; //alloc size
fread( s, sizeof(char), size, fin ); //copy the data from the buffer to s
p=strtok( s, sep );
while( p )
{
++nr;
length+=strlen(p);
p=strtok( NULL, sep );
}
if( !nr )
perror( "There wasn't a word in the file" );
fprintf( fopen( "text.out", "wt" ), "%u", length/nr );
return 0;
}