Cod sursa(job #385344)

Utilizator alexandru92alexandru alexandru92 Data 22 ianuarie 2010 17:07:52
Problema Text Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#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;
}