Char to INT?
-
Hi. I have a Char which containes a number, example 32. How do I convert the char to INT? char cTest[100]="32"; int iTest; now I want to convert the cTest to iTest so it's a integer instead of a char. Any function which can do this? thanks for any info.
-
Hi. I have a Char which containes a number, example 32. How do I convert the char to INT? char cTest[100]="32"; int iTest; now I want to convert the cTest to iTest so it's a integer instead of a char. Any function which can do this? thanks for any info.
atoi.
int iTest = atoi(cTest);
Regards, Alvaro
Well done is better than well said. -- Benjamin Franklin (I actually prefer medium-well.)
-
Hi. I have a Char which containes a number, example 32. How do I convert the char to INT? char cTest[100]="32"; int iTest; now I want to convert the cTest to iTest so it's a integer instead of a char. Any function which can do this? thanks for any info.
-
I think the easiest way would be to simply cast it... iTest = (int)cTest[i]; Wouldn't that work? :~ Programming in binary is as easy as 01 10 11.
Nope, it wouldn't work. Only the first character would be converted, and to it's ASCII value -- which is not what he needs. Regards, Alvaro
Well done is better than well said. -- Benjamin Franklin (I actually prefer medium-well.)
-
Hi. I have a Char which containes a number, example 32. How do I convert the char to INT? char cTest[100]="32"; int iTest; now I want to convert the cTest to iTest so it's a integer instead of a char. Any function which can do this? thanks for any info.
If you don't care about performance :) you can do:
sscanf (cTest, "%d", &iTest);
/ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com
-
I think the easiest way would be to simply cast it... iTest = (int)cTest[i]; Wouldn't that work? :~ Programming in binary is as easy as 01 10 11.
:omg::wtf::omg::wtf::omg: I generally bring up a console project and test my theory if I'm not sure about advice I am about to give :-) Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002 Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
-
Nope, it wouldn't work. Only the first character would be converted, and to it's ASCII value -- which is not what he needs. Regards, Alvaro
Well done is better than well said. -- Benjamin Franklin (I actually prefer medium-well.)
-
atoi.
int iTest = atoi(cTest);
Regards, Alvaro
Well done is better than well said. -- Benjamin Franklin (I actually prefer medium-well.)