943,614 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1941
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Dec 28th, 2008
0

Re: how to save big number into array

C++ Syntax (Toggle Plain Text)
  1. int char2int(char c) {
  2. switch(c) {
  3. case '0': {
  4. return 0;
  5. }
  6. case '1': {
  7. return 1;
  8. }
  9. case '2': {
  10. return 2;
  11. }
  12. case '3': {
  13. return 3;
  14. }
  15. case '4': {
  16. return 4;
  17. }
  18. case '5': {
  19. return 5;
  20. }
  21. case '6': {
  22. return 6;
  23. }
  24. case '7': {
  25. return 7;
  26. }
  27. case '8': {
  28. return 8;
  29. }
  30. case '9': {
  31. return 9;
  32. }
  33. }
  34. }

Take advantage of the fact that '0' through '9' are contiguous on the ASCII chart and that you can subtract characters.

C++ Syntax (Toggle Plain Text)
  1. int char2int(char c)
  2. {
  3. if (c < 48 || c > 57)
  4. return -1; // signifies non-digit/invalid
  5.  
  6. return c - 48; // '0' is 48 in ASCII
  7. }
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,372 posts
since Jan 2008
Dec 28th, 2008
0

Re: how to save big number into array

thank you very much
i'm going to finsh the code- hope it will work.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
harryoma is offline Offline
12 posts
since Dec 2008
Dec 28th, 2008
0

Re: how to save big number into array

@VernonDozier: Yes, you're obviously right, I just wanted to make it as plain as possible for the OP
Last edited by mrboolf; Dec 28th, 2008 at 12:16 pm.
Reputation Points: 134
Solved Threads: 18
Junior Poster
mrboolf is offline Offline
182 posts
since Jun 2008
Dec 28th, 2008
1

Re: how to save big number into array

Quote originally posted by harryoma ...
but getline only works with letters not with numbers
strange... what if my name is U2 ?
Reputation Points: 2023
Solved Threads: 644
Senior Poster
ddanbe is online now Online
3,735 posts
since Oct 2008

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: Binary search
Next Thread in C++ Forum Timeline: quick pointer question





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


Follow us on Twitter


© 2011 DaniWeb® LLC