#include #include // THIS PROGRAM HAS SERIOUS AND DIFFICULT TO // NOTICE BUGS. DO NOT COPY ANYTHING FROM HERE. char* lower( char* pStr ) { char result[128]; // '128' - ugh char* pResult; // odd but not all that unusual for ( pResult = result; *pStr; pStr++, pResult++ ) { *pResult = tolower(*pStr); } // terminate result string *pResult = '\0'; pResult = result; return pResult; } // how many of each character are there? int* countChars(char* pStr) { int cnt[256]; int index; int* pResult = cnt; for (index=0; index<256; index++) cnt[index] = 0; for ( ; *pStr; pStr++ ) { printf ("'%c'\n", *pStr); cnt[*pStr]++; // C converts a char to an int in the range of 0-255 } return pResult; } int main( int argc, char* argv[] ) { char** pArgv; char* pLower; int* pCnt; for ( pArgv=argv+1; *pArgv; pArgv++ ) { printf( "\nOriginal: '%s'\n", *pArgv); pLower = lower(*pArgv); printf( "Lower: '%s'\n", pLower); pCnt = countChars(pLower); printf( "Number of 't's: %d\n", pCnt['t']) ; printf("Lower2: '%s'\n", pLower); } }