![]() |
| ||
| Need help to convert a string to an integer Hi all, I am new to C programming and need some of your help. I am trying to convert a string(ex. 25,000) to an integer. I use the atoi function to do the conversion, however, it only reads the initial portion of the string by stopping at the first non-numerical character. In my case, it stores the value of "25" rather than "25000". How do I remove the comma and convert it to an integer? Please advise, thanks in advance. Carol int result; extract_value(char* param_name) |
| ||
| Re: Need help to convert a string to an integer you can remove the comma by shifting all other characters left one place, assuming the string is in read/write memory. char str[] = "25,000"; |
| ||
| Re: Need help to convert a string to an integer >I use the atoi function to do the conversion Take a look at strtol(), it would be better, atoi() has poor error handling |
| ||
| Re: Need help to convert a string to an integer check this out. compile it and run it and see how it works. the function "stripCharacters" will strip out any undesired characters using the standard library function strtok... very powerful function, learn to use it. #include <stdio.h> . |
| ||
| Re: Need help to convert a string to an integer bah. extra credit if you fix my bug :P |
| ||
| Re: Need help to convert a string to an integer Quote:
exit();) Quote:
|
| ||
| Re: Need help to convert a string to an integer meanie :( lol :D |
| All times are GMT -4. The time now is 7:05 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC