943,898 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 6830
  • C RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Oct 21st, 2007
0

Re: Program calculate letter occurence in a sentence

Click to Expand / Collapse  Quote originally posted by Aia ...
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. }

Aiks, i really fresh in C. Your coding contain some element i never learn before. haha But thx, i copy paste the code and run it, it work perfectly.
Reputation Points: 14
Solved Threads: 0
Light Poster
bobei89 is offline Offline
26 posts
since Oct 2007
Oct 21st, 2007
0

Re: Program calculate letter occurence in a sentence

Click to Expand / Collapse  Quote originally posted by ithelp ...
Cannot you use std::string apis ?
i never learn about it. haha
Reputation Points: 14
Solved Threads: 0
Light Poster
bobei89 is offline Offline
26 posts
since Oct 2007
Oct 21st, 2007
0

Re: Program calculate letter occurence in a sentence

Click to Expand / Collapse  Quote originally posted by bobei89 ...
Aiks, i really fresh in C. Your coding contain some element i never learn before.
Learning is a process always on going.
Click to Expand / Collapse  Quote originally posted by bobei89 ...
i copy paste the code and run it, it work perfectly.
No copy and paste. Write it. Practice. Write it again. Practice again.
You'll learn nothing by just coping and paste and looking at it, and rejoicing that it works.
You don't know that it works until you understand why it does.

Click to Expand / Collapse  Quote originally posted by bobei89 ...
Cannot you use std::string apis ?
>i never learn about it. haha
That's not C. Don't pay attention to it.
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
Oct 22nd, 2007
0

Re: Program calculate letter occurence in a sentence

Yosh, Thank you all who reply my thread. Problem solved.
Thx alot ya.
Reputation Points: 14
Solved Threads: 0
Light Poster
bobei89 is offline Offline
26 posts
since Oct 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: c Compiler (Not C++)
Next Thread in C Forum Timeline: binary





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC