#include #include #include #include int iswhite(char c) { if(c==' ' || c=='\t' || c=='\n') return(1); else return(0); } int main(int argc,char *argv[]) { // counter int klib = 0; // #include int kheaderfile = 0; // XXX.h int kauto = 0; // auto int kbreak = 0; // break int kcase = 0; // case int kchar = 0; // char int kconst = 0; // const int kcontinue = 0; // continue int kdefault = 0; // default int kdo = 0; // do int kdouble = 0; // double int kelse = 0; // else int kenum = 0; // enum int kextern = 0; // extern int kfloat = 0; // float int kfor = 0; // for int kgoto = 0; // goto : int kif = 0; // if int kint = 0; // int int klong = 0; // long int kregister = 0; // register int kreturn = 0; // return int kshort = 0; // short int ksigned = 0; // signed int ksizeof = 0; // sizeof int kstatic = 0; // static int kstruct = 0; // struct int kswitch = 0; // switch int ktypedef = 0; // typedef int kunion = 0; // union int kunsigned = 0; // unsigned int kvoid = 0; // void int kvolatile = 0; // volatile int kwhile = 0; // while //counter int string = 0; // " " int character = 0; // ' ' //counter int semi = 0; // ; int questionmark = 0; // ? int comma = 0; // , int colon=0; int open_c = 0; // ( int close_c = 0; // ) int open_s = 0; // [ int close_s = 0; // ] int open_f = 0; // { int close_f = 0; // } //function & var int var =0; //number int num = 0; int onedot=0; // comment int comment =0 ; // operater int andand = 0; int andonly = 0; int oror = 0; int oronly = 0; int plp = 0; // ++ int ple = 0; // += int pl = 0; // + int mim = 0; // -- int mia = 0; // -> int mie = 0; // -= int mi = 0; // - int mue = 0; // *= int mu = 0; // * int comment99 = 0; // // int die = 0; // /= int di = 0; // / int moe = 0; // %= int mo = 0; // % int araw = 0; // >> int largee=0; // >= int large =0; // > int smalle=0; // <= int small =0; // < int ee = 0; // == int e = 0; // = int note = 0; // != int not = 0; // ! int dotdot=0; /* new in here */ /* end new in here */ char array[100000]; //store whole file to an array int arraysize = 0; int tmp=0; char tmparray[255]; char tmparray2[255]; int tmpnum=0; int oldnum=0; register int pos=0; // current position register char *ptr; int totalcount=0; FILE *fptr = NULL; FILE *nptr = NULL; FILE *cptr = NULL; FILE *sptr = NULL; FILE *vptr = NULL; nptr=fopen("number1.txt","w"); cptr=fopen("char1.txt","w"); sptr=fopen("str1.txt","w"); vptr=fopen("varfunc1.txt","w"); if(argc!=2) { printf("Please enter program name followed by a c program name\n"); exit(1); } if( (fptr=fopen(argv[1],"r"))==NULL) { printf("Cannot open file : %s\n",argv[1]); exit(1); } ptr=array; while( (*ptr=fgetc(fptr))!=EOF) { if(iswhite(*ptr)==1) continue; ptr++; arraysize++; } *ptr='\0'; fclose(fptr); ptr=array; while(pos%d\n",pos,*ptr,arraysize); // miss all space while(iswhite(*ptr) && *ptr) { ptr++; pos++; } // comment if((*ptr=='/') && ( *(ptr+1) == '*' )) { do { while(*ptr!='*') { ptr++; pos++; } ptr++; pos++; }while(*ptr!='/'); ptr++; pos++; comment++; continue; } // string if(*ptr=='\"') { do { ptr++; pos++; if(*ptr!='\"') putc(*ptr,sptr); if((*ptr=='\"') && (*(ptr-1)=='\\')) { ptr++; pos++; putc(*ptr,sptr); } }while(*ptr!='\"'); putc('\n',sptr); ptr++; pos++; string++; continue; } // character if(*ptr=='\'') { do { ptr++; pos++; if(*ptr!='\'') putc(*ptr,cptr); if( (*ptr=='\'') && (*(ptr-1)=='\\') ) { ptr++; pos++; putc(*ptr,cptr); } }while(*ptr!='\''); putc('\n',cptr); ptr++; pos++; character++; continue; } // keyword if( (pos<=arraysize-10) && (strncmp("#include <",ptr,10)==0) ) { ptr+=10; pos+=10; klib++; do { ptr++; pos++; }while(*ptr!='>'); ptr++; pos++; kheaderfile++; continue; } if( (pos<=arraysize-8) && (strncmp("#include",ptr,8)==0) ) { ptr+=8; pos+=8; klib++; continue; } if( (pos<=arraysize-4) && (strncmp("auto",ptr,4)==0) ) { ptr+=4; pos+=4; kauto++; continue; } if( (pos<=arraysize-5) && (strncmp("break",ptr,5)==0) ) { ptr+=5; pos+=5; kbreak++; continue; } if( (pos<=arraysize-4) && (strncmp("case",ptr,4)==0) ) { ptr+=4; pos+=4; kcase++; continue; } if( (pos<=arraysize-4) && (strncmp("char",ptr,4)==0) && (*(ptr+4)= ==' ')) { ptr+=4; pos+=4; kchar++; continue; } if( (pos<=arraysize-5) && (strncmp("const",ptr,5)==0) && (*(ptr+5)= ==' ')) { ptr+=5; pos+=5; kconst++; continue; } if( (pos<=arraysize-8) && (strncmp("continue",ptr,8)==0) ) { ptr+=8; pos+=8; kcontinue++; continue; } if( (pos<=arraysize-7) && (strncmp("default",ptr,7)==0) ) { ptr+=7; pos+=7; kdefault++; continue; } if( (pos<=arraysize-2) && (strncmp("do",ptr,2)==0) ) { ptr+=2; pos+=2; kdo++; continue; } if( (pos<=arraysize-6) && (strncmp("double",ptr,6)==0) && (*(ptr+6)= ==' ')) { ptr+=6; pos+=6; kdouble++; continue; } if( (pos<=arraysize-4) && (strncmp("else",ptr,4)==0) ) { ptr+=4; pos+=4; kelse++; continue; } if( (pos<=arraysize-4) && (strncmp("enum",ptr,4)==0) ) { ptr+=4; pos+=4; kenum++; continue; } if( (pos<=arraysize-6) && (strncmp("extern",ptr,6)==0) ) { ptr+=6; pos+=6; kextern++; continue; } if( (pos<=arraysize-5) && (strncmp("float",ptr,5)==0) && (*(ptr+5)= ==' ')) { ptr+=5; pos+=5; kfloat++; continue; } if( (pos<=arraysize-3) && (strncmp("for",ptr,3)==0) ) { ptr+=3; pos+=3; kfor++; continue; } if( (pos<=arraysize-4) && (strncmp("goto",ptr,4)==0) ) { ptr+=4; pos+=4; kgoto++; continue; } if( (pos<=arraysize-2) && (strncmp("if",ptr,2)==0) ) { ptr+=2; pos+=2; kif++; continue; } if( (pos<=arraysize-3) && (strncmp("int",ptr,3)==0) && (*(ptr+3)== =' ')) { ptr+=3; pos+=3; kint++; continue; } if( (pos<=arraysize-4) && (strncmp("long",ptr,4)==0) && (*(ptr+4)= ==' ')) { ptr+=4; pos+=4; klong++; continue; } if( (pos<=arraysize-8) && (strncmp("register",ptr,8)==0) ) { ptr+=8; pos+=8; kregister++; continue; } if( (pos<=arraysize-6) && (strncmp("return",ptr,6)==0) ) { ptr+=6; pos+=6; kreturn++; continue; } if( (pos<=arraysize-5) && (strncmp("short",ptr,5)==0) && (*(ptr+5)= ==' ')) { ptr+=5; pos+=5; kshort++; continue; } if( (pos<=arraysize-6) && (strncmp("signed",ptr,6)==0) ) { ptr+=6; pos+=6; ksigned++; continue; } if( (pos<=arraysize-6) && (strncmp("sizeof",ptr,6)==0) ) { ptr+=6; pos+=6; ksizeof++; continue; } if( (pos<=arraysize-6) && (strncmp("static",ptr,6)==0) ) { ptr+=6; pos+=6; kstatic++; continue; } if( (pos<=arraysize-6) && (strncmp("struct",ptr,6)==0) ) { ptr+=6; pos+=6; kstruct++; continue; } if( (pos<=arraysize-6) && (strncmp("switch",ptr,6)==0) ) { ptr+=6; pos+=6; kswitch++; continue; } if( (pos<=arraysize-7) && (strncmp("typedef",ptr,7)==0) ) { ptr+=7; pos+=7; ktypedef++; continue; } if( (pos<=arraysize-5) && (strncmp("kunion",ptr,5)==0) ) { ptr+=5; pos+=5; kunion++; continue; } if( (pos<=arraysize-8) && (strncmp("unsigned",ptr,8)==0) ) { ptr+=8; pos+=8; kunsigned++; continue; } if( (pos<=arraysize-4) && (strncmp("void",ptr,4)==0) ) { ptr+=4; pos+=4; kvoid++; continue; } if( (pos<=arraysize-8) && (strncmp("volatile",ptr,8)==0) ) { ptr+=8; pos+=8; kvolatile++; continue; } if( (pos<=arraysize-5) && (strncmp("while",ptr,5)==0) ) { ptr+=5; pos+=5; kwhile++; continue; } // var function num if((*ptr=='_') || (isalpha(*ptr) ) ) { do { putc(*ptr,vptr); ptr++; pos++; }while( (*ptr=='_') || (isalpha(*ptr) ) || (isdigit(*ptr)) ); var++; putc('\n',vptr); continue; } if( (isdigit(*ptr)) || (*ptr=='.' && isdigit(*(ptr+1))) || ((*ptr== ='-') && (strrchr("+*/%",(*(ptr-1)))) && ((isdigit(*(ptr+1)))||( *(ptr+1)= =='.')))) { if(*ptr=='.') onedot++; do { putc(*ptr,nptr); ptr++; pos++; }while( (isdigit(*ptr)) || *ptr=='.' ); num++; putc('\n',nptr); continue; } // punctuation if(*ptr=='?') { ptr++; pos++; questionmark++; continue; } if(*ptr==';') { ptr++; pos++; semi++; continue; } if(*ptr==':') { ptr++; pos++; colon++; continue; } if(*ptr==',') { ptr++; pos++; comma++; continue; } if(*ptr=='(') { ptr++; pos++; open_c++; continue; } if(*ptr==')') { ptr++; pos++; close_c++; continue; } if(*ptr=='[') { ptr++; pos++; open_s++; continue; } if(*ptr==']') { ptr++; pos++; close_s++; continue; } if(*ptr=='}') { ptr++; pos++; close_f++; continue; } if(*ptr=='{') { ptr++; pos++; open_f++; continue; } // operator if((*ptr=='&') && ( *(ptr+1)=='&') ) // != { ptr+=2; pos+=2; andand++; continue; } if(*ptr=='&') // ! { ptr++; pos++; andonly++; continue; } if((*ptr=='|') && ( *(ptr+1)=='|') ) // != { ptr+=2; pos+=2; oror++; continue; } if(*ptr=='|') // ! { ptr++; pos++; oronly++; continue; } if((*ptr=='!') && ( *(ptr+1)=='=') ) // != { ptr+=2; pos+=2; note++; continue; } if(*ptr=='!') // ! { ptr++; pos++; not++; continue; } if((*ptr=='+') && ( *(ptr+1)=='+') ) // ++ { ptr+=2; pos+=2; plp++; continue; } if((*ptr=='+') && ( *(ptr+1)=='=') ) // += { ptr+=2; pos+=2; ple++; continue; } if(*ptr=='+') // + { ptr++; pos++; pl++; continue; } if((*ptr=='-') && ( *(ptr+1)=='-') ) // -- { ptr+=2; pos+=2; mim++; continue; } if((*ptr=='-') && ( *(ptr+1)=='>') ) // -> { ptr+=2; pos+=2; mia++; continue; } if((*ptr=='-') && ( *(ptr+1)=='=') ) // -= { ptr+=2; pos+=2; mie++; continue; } if(*ptr=='-') // - { ptr++; pos++; mi++; continue; } if((*ptr=='*') && ( *(ptr+1)=='=') ) // *= { ptr+=2; pos+=2; mue++; continue; } if(*ptr=='*') // * { ptr++; pos++; mu++; continue; } if((*ptr=='/') && ( *(ptr+1)=='/')) { do { ptr++; pos++; }while(*ptr!='\n'); comment99++; continue; } if((*ptr=='/') && ( *(ptr+1)=='=') ) { ptr+=2; pos+=2; die++; continue; } if(*ptr=='/') { ptr++; pos++; di++; continue; } if((*ptr=='%') && ( *(ptr+1)=='=') ) { ptr+=2; pos+=2; moe++; continue; } if(*ptr=='%') { ptr++; pos++; mo++; continue; } if((*ptr=='>') && ( *(ptr+1)=='>') ) { ptr+=2; pos+=2; araw++; continue; } if((*ptr=='>') && ( *(ptr+1)=='=') ) { ptr+=2; pos+=2; largee++; continue; } if(*ptr=='>') { ptr++; pos++; large++; continue; } if((*ptr=='<') && ( *(ptr+1)=='=') ) { ptr+=2; pos+=2; smalle++; continue; } if(*ptr=='<') { ptr++; pos++; small++; continue; } if((*ptr=='=') && ( *(ptr+1)=='=') ) { ptr+=2; pos+=2; ee++; continue; } if(*ptr=='=') // = { ptr++; pos++; e++; continue; } if(*ptr=='.') { ptr++; pos++; dotdot++; continue; } printf("special - %d<%c>%d\n",pos,*ptr,arraysize); ptr++; pos++; } totalcount+=klib; totalcount+=kheaderfile; totalcount+=kauto; totalcount+=kbreak; totalcount+=kcase; totalcount+=kchar; totalcount+=kconst; totalcount+= kcontinue; totalcount+= kdefault ; totalcount+= kdo; totalcount+= kdouble; totalcount+=kelse; totalcount+= kenum; totalcount+= kextern; totalcount+= kfloat ; totalcount+=kfor; totalcount+=kgoto; totalcount+= kif; totalcount+=kint; totalcount+= klong ; totalcount+= kregister; totalcount+= kreturn; totalcount+= kshort; totalcount+= ksigned; totalcount+=ksizeof; totalcount+=kstatic; totalcount+=kstruct; totalcount+= kswitch ; totalcount+=ktypedef; totalcount+= kunion; totalcount+= kunsigned ; totalcount+= kvoid ; totalcount+= kvolatile; totalcount+= kwhile; totalcount+= string ; totalcount+= character; totalcount+=semi; totalcount+=questionmark; totalcount+=comma; totalcount+=colon; totalcount+=open_c; totalcount+=close_c; totalcount+=open_s ; totalcount+=close_s ; totalcount+=open_f ; totalcount+=close_f ; totalcount+=var; totalcount+=num ; totalcount+=onedot; totalcount+=comment; totalcount+=andand; totalcount+=andonly; totalcount+=oror; totalcount+=oronly; totalcount+=plp ; totalcount+= ple ; totalcount+=pl ; totalcount+=mim; totalcount+= mia ; totalcount+=mie ; totalcount+= mi ; totalcount+=mue ; totalcount+=mu ; totalcount+=comment99; totalcount+= die; totalcount+=di ; totalcount+=moe ; totalcount+= mo ; totalcount+= araw ; totalcount+=largee; totalcount+= large; totalcount+=smalle; totalcount+= small; totalcount+= ee; totalcount+= e; totalcount+= note; totalcount+=not; totalcount+=dotdot; //keyword fclose(nptr); fclose(cptr); fclose(vptr); fclose(sptr); system("sort number1.txt -o number1.txt"); system("sort char1.txt -o char1.txt"); system("sort str1.txt -o str1.txt"); system("sort varfunc1.txt -o varfunc1.txt"); nptr=fopen("number1.txt","r"); cptr=fopen("char1.txt","r"); sptr=fopen("str1.txt","r"); vptr=fopen("varfunc1.txt","r"); printf("Total count = %d\n",totalcount); if(klib!=0) printf("%d #include: %.5f\n",klib,(float)klib/totalcount); if(kheaderfile!=0) printf("%d headerfile: %.5f\n",kheaderfile,(float)khe= aderfile/totalcount); if(kbreak!=0) printf("% dbreak: %.5f\n",kbreak,(float)kbreak/totalcount); if(kauto!=0) printf("% dauto: %.5f\n",kauto,(float)kauto/totalcount); if(kcase!=0) printf("% dcase: %.5f\n",kcase,(float)kcase/totalcount); if(kchar!=0) printf("%d char: %.5f\n",kchar,(float)kchar/totalcount); if(kconst!=0) printf("%d kconst: %.5f\n",kconst,(float)kconst/totalcount= ); if(kdefault!=0) printf("%d default: %.5f\n",kdefault,(float)kdefault/tot= alcount); if(kdo!=0) printf("%d do: %.5f\n",kdo,(float)kdo/totalcount); if(kdouble!=0) printf("%d double: %.5f\n",kdouble,(float)kdouble/totalco= unt); if(kelse!=0) printf("%d else: %.5f\n",kelse,(float)kelse/totalcount); if(kenum!=0) printf("%d enum: %.5f\n",kenum,(float)kenum/totalcount); if(kextern=0) printf("%d extern: %.5f\n",kextern,(float)kextern/totalcou= nt); if(kfloat!=0) printf("%d float: %.5f\n",kfloat,(float)kfloat/totalcount); if(kfor!=0) printf("%d for: %.5f\n",kfor,(float)kfor/totalcount); if(kgoto!=0) printf("%d goto: %.5f\n",kgoto,(float)kgoto/totalcount); if(kif!=0) printf("%d if: %.5f\n",kif,(float)kif/totalcount); if(kint!=0) printf("%d int: %.5f\n",kint,(float)kint/totalcount); if(klong!=0) printf("%d long: %.5f\n",klong,(float)klong/totalcount); if(kregister!=0) printf("%d register: %.5f\n",kregister,(float)kregister= /totalcount); if(kreturn!=0) printf("%d kreturn: %.5f\n",kreturn,(float)kreturn/totalc= ount); if(kshort!=0) printf("%d short: %.5f\n",kshort,(float)kshort/totalcount); if(ksigned!=0) printf("%d signed: %.5f\n",ksigned,(float)ksigned/totalco= unt); if(ksizeof!=0) printf("%d sizeof: %.5f\n",ksizeof,(float)ksizeof/totalco= unt); if(kstatic!=0) printf("%d static: %.5f\n",kstatic,(float)kstatic/totalco= unt); if(kstruct!=0) printf("%d struct: %.5f\n",kstruct,(float)kstruct/totalco= unt); if(kswitch!=0) printf("%d switch: %.5f\n",kswitch,(float)kswitch/totalco= unt); if(ktypedef!=0) printf("%d typedef: %.5f\n",ktypedef,(float)ktypedef/tot= alcount); if(kunion!=0) printf("%d union: %.5f\n",kunion,(float)kunion/totalcount); if(kunsigned!=0) printf("%d unsigned: %.5f\n",kunsigned,(float)kunsigned= /totalcount); if(kvoid!=0) printf("%d void: %.5f\n",kvoid,(float)kvoid/totalcount); if(kvolatile!=0) printf("%d volatile: %.5f\n",kvolatile,(float)kvolatile= /totalcount); if(kwhile!=0) printf("%d while: %.5f\n",kwhile,(float)kwhile/totalcount); //string,character if(character!=0) printf("%d character: %.5f\n",character,(float)characte= r/totalcount); if(string!=0) printf("%d string: %.5f\n",string,(float)string/totalcount= ); //punctuation if(semi!=0) printf("%d ;: %.5f\n",semi,(float)semi/totalcount); if(questionmark!=0) printf("%d ?: %.5f\n",questionmark,(float)questionma= rk/totalcount); if(colon!=0) printf("%d :: %.5f\n",colon,(float)colon/totalcount); if(comma!=0) printf("%d ,: %.5f\n",comma,(float)comma/totalcount); if(open_c!=0) printf("%d (: %.5f\n",open_c,(float)open_c/totalcount); if(open_c!=0) printf("%d ): %.5f\n",open_c,(float)open_c/totalcount); if(open_s!=0) printf("%d [: %.5f\n",open_s,(float)open_s/totalcount); if(open_s!=0) printf("%d ]: %.5f\n",open_s,(float)open_s/totalcount); if(open_f!=0) printf("%d {: %.5f\n",open_f,(float)open_f/totalcount); if(open_f!=0) printf("%d }: %.5f\n",open_f,(float)open_f/totalcount); //function & var & num & comment if(var!=0) printf("%d var & func: %.5f\n",var,(float)var/totalcount); if(num!=0) printf("%d number: %.5f\n",num,(float)num/totalcount); if(comment!=0) printf("%d comment: %.5f\n",comment,(float)comment/totalc= ount); // operater if(andand!=0) printf("%d &&: %.5f\n",andand,(float)andand/totalcount); if(andonly!=0) printf("%d &: %.5f\n",andonly,(float)andonly/totalcount); if(oror!=0) printf("%d ||: %.5f\n",oror,(float)oror/totalcount); if(oronly!=0) printf("%d |: %.5f\n",oronly,(float)oronly/totalcount); if(plp!=0) printf("%d ++: %.5f\n",plp,(float)plp/totalcount); if(ple!=0) printf("%d +=: %.5f\n",ple,(float)ple/totalcount); if(pl!=0) printf("%d +: %.5f\n",pl,(float)pl/totalcount); if(mim!=0) printf("%d --: %.5f\n",mim,(float)mim/totalcount); if(mia!=0) printf("%d ->: %.5f\n",mia,(float)mia/totalcount); if(mie!=0) printf("%d -=: %.5f\n",mie,(float)mie/totalcount); if(mi!=0) printf("%d -: %.5f\n",mi,(float)mi/totalcount); if(mue!=0) printf("%d *=: %.5f\n",mue,(float)mue/totalcount); if(mu!=0) printf("%d *: %.5f\n",mu,(float)mu/totalcount); if(comment99!=0) printf("%d //: %.5f\n",comment99,(float)comment99/total= count); if(die!=0) printf("%d /=: %.5f\n",die,(float)die/totalcount); if(di!=0) printf("%d /: %.5f\n",di,(float)di/totalcount); if(moe!=0) printf("%d %=: %.5f\n",moe,(float)moe/totalcount); if(mo!=0) printf("%d %: %.5f\n",mo,(float)mo/totalcount); if(araw!=0) printf("%d >>: %.5f\n",araw,(float)araw/totalcount); if(largee!=0) printf("%d >=: %.5f\n",largee,(float)largee/totalcount); if(large!=0) printf("%d >: %.5f\n",large,(float)large/totalcount); if(smalle!=0) printf("%d <=: %.5f\n",smalle,(float)smalle/totalcount); if(small!=0) printf("%d <: %.5f\n",small,(float)small/totalcount); if(ee!=0) printf("%d ==: %.5f\n",ee,(float)ee/totalcount); if(e!=0) printf("%d =: %.5f\n",e,(float)e/totalcount); if(note!=0) printf("%d !=: %.5f\n",note,(float)note/totalcount); if(not!=0) printf("%d !: %.5f\n",not,(float)not/totalcount); if(dotdot!=0) printf("%d .: %.5f\n",dotdot,(float)dotdot/totalcount); tmpnum=0; oldnum=-9394; fscanf(nptr,"%d",&tmpnum); while(!feof(nptr)) { tmp=0; oldnum=tmpnum; do { fscanf(nptr,"%d",&tmpnum); tmp++; }while(!feof(nptr) && oldnum==tmpnum); printf("Num: %d\tTotal:%d\tP(num): %.5f\tP(Total): %.5f\n",oldnum,tmp,((f= loat)tmp/num),((float)tmp/totalcount)); } fclose(nptr); fscanf(cptr,"%s",tmparray); while(!feof(cptr)) { tmp=0; strcpy(tmparray2,tmparray); do { fscanf(cptr,"%s",tmparray); tmp++; }while(!feof(cptr) && strncmp(tmparray2,tmparray,2)==0); printf("char:%s\tTotal: %d\tP(char)%.5f\tP(total): %.5f\n",tmparray2,tmp,= ((float)tmp/character),((float)tmp/totalcount)); } fclose(cptr); fscanf(vptr,"%s",tmparray); while(!feof(vptr)) { tmp=0; strcpy(tmparray2,tmparray); do { fscanf(vptr,"%s",tmparray); tmp++; }while(!feof(vptr) && strcmp(tmparray2,tmparray)==0); printf("Func&Var:%s\tTotal: %d\tP(num) :%.5f\tP(total) :%.5f\n",tmparray2= ,tmp,((float)tmp/var),((float)tmp/totalcount)); } fclose(vptr); fgets(tmparray,256,sptr); while(!feof(sptr)) { tmp=0; strcpy(tmparray2,tmparray); do { fgets(tmparray,256,sptr); tmp++; }while(!feof(sptr) && strcmp(tmparray2,tmparray)==0); printf("String:%sTotal: %d\tP(num): %.5f\tP(total): %.5f\n",tmparray2,tmp= ,((float)tmp/string),((float)tmp/totalcount)); } fclose(sptr); return(0); } /* ver 1.01 */