How does one parse an integer to string(char* || char[])
in C? Is there an equivalent to the Integer.parseInt(String)
method from Java in C?
相关问题
- Multiple sockets for clients to connect to
- Correctly parse PDF paragraphs with Python
- how to split a list into a given number of sub-lis
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
This is discussed in Steve Summit's C FAQs.
You can try:
that should do the trick.
If you want to convert an integer to string, try the function
snprintf()
.If you want to convert a string to an integer, try the function
sscanf()
oratoi()
oratol()
.To convert an int to a string:
You can also do it for doubles:
To convert a string to an int:
See http://www.acm.uiuc.edu/webmonkeys/book/c_guide/ for the documentation of these functions.
The Java
parseInt()
function parses a string to return an integer. An equivalent C function isatoi()
. However, this doesn't seem to match the first part of your question. Do you want to convert from an integer to a string, or from a string to an integer?You may want to take a look at the compliant solution on this site.