how to save big number into array

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jan 2008
Posts: 3,813
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: how to save big number into array

 
0
  #11
Dec 28th, 2008
  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.

  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. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 12
Reputation: harryoma is an unknown quantity at this point 
Solved Threads: 0
harryoma harryoma is offline Offline
Newbie Poster

Re: how to save big number into array

 
0
  #12
Dec 28th, 2008
thank you very much
i'm going to finsh the code- hope it will work.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 182
Reputation: mrboolf will become famous soon enough mrboolf will become famous soon enough 
Solved Threads: 18
mrboolf mrboolf is offline Offline
Junior Poster

Re: how to save big number into array

 
0
  #13
Dec 28th, 2008
@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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,917
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 274
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: how to save big number into array

 
1
  #14
Dec 28th, 2008
Originally Posted by harryoma
but getline only works with letters not with numbers
strange... what if my name is U2 ?
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC