converting string to integer
Author |
Message |
Fonzie
|
Posted: Thu Sep 27, 2007 4:59 pm Post subject: converting string to integer |
|
|
I need to figure out how to convert a string filled with numbers into an unsigned long long int. The string will have anywhere between 1 and 10 characters. I want it so that the string "9876543210" becomes the integer number 9876543210. for this program I am only allowed to use functions in the string.h library, getchar(), putchar() and printf(). Thanks in advance. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Thu Sep 27, 2007 5:08 pm Post subject: RE:converting string to integer |
|
|
Start by figuring out how to get an individual character out of that string (say c = "2") while keeping track of its position from the end (n = 3[rd] char)
Converting a character to an integer is easy, think ASCII values.
That n will let you know where in the string it was.
c = 2
n = 3
c * 10 ** (n-1) = 200
Then just add all of that up. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Fonzie
|
Posted: Fri Sep 28, 2007 2:01 pm Post subject: Re: converting string to integer |
|
|
that worked, thanks a lot. |
|
|
|
|
|
|
|