Conversion, string to int
-
Are you looking for the function atoi? this is an old but much maligned function. If it is you you only have to say "Thanks masked man - you have saved my life" go cobol young man - go cobol
My neighbours think I am crazy - but they don't know that I have a trampoline. All they see my head bobbing up and down over the fence every five seconds
-
See the FAQ 6.3: How can I change a number into its string representation, or vice versa?[^] --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber You cannot stop me with paramecium alone!
-
See the FAQ 6.3: How can I change a number into its string representation, or vice versa?[^] --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber You cannot stop me with paramecium alone!
cobol just told you, how to convert from str to int so you have that right? int x = atoi("123456"); now to change that back to an int? ok right out of MSDN char *string, *stopstring; double x; long l; // or int int base; unsigned long ul; string = "3.1415926This stopped it"; x = strtod( string, &stopstring ); printf( "string = %s\n", string ); printf(" strtod = %f\n", x ); printf(" Stopped scan at: %s\n\n", stopstring ); string = "-10110134932This stopped it"; l = strtol( string, &stopstring, 10 ); printf( "string = %s", string ); printf(" strtol = %ld", l ); printf(" Stopped scan at: %s", stopstring ); string = "10110134932"; Best Wishes and Happy Holiday's, ez_way
-
You can use the
atoi()
function if it a CString. If it is LPTSTR or some other string stuff I prefer writing them on an invisible static text box and retrieving them as an interger. I hope this helps! Well... I am a beginner ...Scolinks wrote: You can use the atoi() function if it a CString. If it is LPTSTR or some other string stuff I prefer writing them on an invisible static text box and retrieving them as an interger. I hope this helps! Well... I am a beginner ... Yuck! (the static text box thing) But forgivable for a beginner (just :-)) I think it's time you were introduced to the boost library, and in particular the lexical_cast<> template. Also note that an LPTSTR (long pointer to a TCHAR string) can be one of two things - a pointer to a char array (char *), or a pointer to a wide-char string (wchar_t *, which is a full type in VC.NET, and a typedef for short in VC6) The T bit is the TCHAR thing mentioned earlier - TCHAR means char or wchar_t, depending on if you are building an ANSI/ASCII version of your code, or a UNICODE one. I would suggest that you look up the relevant functions for conversions, which can handle unicode or ansi strings as necessary (eg, _tcstoul for converting a LPTSTR to an unsigned long). HTH -- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky