RSS Forums RSS
Please support our C advertiser: Programming Forums

Program calculate letter occurence in a sentence

Join Date: Dec 2006
Posts: 1,625
Reputation: Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold 
Rep Power: 13
Solved Threads: 122
Aia's Avatar
Aia Aia is offline Offline
Posting Virtuoso

Re: Program calculate letter occurence in a sentence

  #7  
Oct 21st, 2007
Never define main as void return. Start defining main as int main( void ) or int main ( int argc, char *argv[] ) if you are expecting arguments from the command line.

>Sorry i never learn about <ctype.h>, isalpha, islower and isupper, is there other way???
  1. #include <stdio.h>
  2. /* #define ALL_CHARACTER */ /* enable for use all characters in RANGE */
  3. /* #define RANGE */ /* enable for only lower case */
  4. #ifdef RANGE
  5. #define START 'a'
  6. #endif
  7. #ifndef RANGE
  8. #define START 'A'
  9. #endif
  10.  
  11. int main( void )
  12. {
  13. char character[256] = { 0 };
  14. int c = '\0';
  15.  
  16. puts( "Enter some text:" );
  17.  
  18. while ( ( c = getchar() ) != '\n' && c != EOF )
  19. {
  20. ++character[c];
  21. }
  22. for ( c = START; c <= 'z'; c++ )
  23. {
  24. #ifndef ALL_CHARACTER
  25. if ( character[c] )
  26. #endif
  27. printf( "%c = %d\n", c, character[c] );
  28. }
  29. getchar();
  30. return 0;
  31. }
Last edited by Aia : Oct 21st, 2007 at 1:02 am.
At the very moment that I find myself in the side of the mayority, I will know that I need to re-think my ideas. ~ In my book.
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:27 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC