
-----------------------------------
Fonzie
Thu Sep 27, 2007 4:59 pm

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.

-----------------------------------
Tony
Thu Sep 27, 2007 5:08 pm

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.

-----------------------------------
Fonzie
Fri Sep 28, 2007 2:01 pm

Re: converting string to integer
-----------------------------------
that worked, thanks a lot.
