//Bo Zhang //Homwork 7 //Count A #include "header.h" long int CharVect[256]; int main(void) { time_t start,end; double dif; unsigned char c; //declates char as unsigned to avoid segmentation error int x; time(&start); while(scanf("%c",&c)>0) //scans file for 1 character, if none is found, 0 should be returns ending the loop { CharVect[(int)(c)]=CharVect[(int)(c)]+1; //adds 1 to the part of the vector storing value for the found character } for(x=0; x<16; x++) //the program prints a space for unprintable character { if(CharVect[x]!=0) printf("%ld\t %ld\n",x,CharVect[x]); } for(x=16; x<128; x++) { if(CharVect[x]!=0) printf("%ld\t%c %ld\n",x,(char)(x),CharVect[x]);//prints the code, symbol, and the number of occurences } for(x=128; x<256; x++) { if(CharVect[x]!=0) printf("%ld\t %ld\n",x,CharVect[x]); } time (&end); //ends timer and computes difference in time dif = difftime (end,start); printf("time=%lf\n",dif); return 0; }