Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* WORD COUNT UTILITY
- wc.c by FrozenVoid
- licensed under UFIL1.02 http://pastebin.com/L3p9XK3T
- @..\dmc -gg -Nc -Jm -o+all -o-dv %1.c -o%1.exe
- */
- #include "void.h" // http://pastebin.com/L4bT9u1b
- STDSTART
- u1 anum[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- u1 at[256]={0};u4 i=0;
- for(i=0;i<(sizeof(anum));i++){at[anum[i]]=1;}
- if(argc<2){epr("Syntax: wc filename");exit(1);}
- u4 fsize;u1* c=getfile(argv[1],&fsize);
- if(!fsize||!c){epr("File %s cannot be opened or empty",argv[1]);exit(2);};
- u8 exstart=rdtsc();//start of operation
- u4 count=0;u4 old=0,state=0;
- for(i=0;i<fsize;i++){
- state=at[c[i]];//if 1^1 0^0 same word.
- count+=(old^state);old=state;};
- count>>=1;
- u8 endbench=rdtsc()-exstart;
- pr("%"PRIu32" words in file %s \n cycles spent:%"PRIu64,count,argv[1],endbench);
- STDEND
Advertisement
Add Comment
Please, Sign In to add comment