Forum: Compiler & IDEs Int to Str Konvertierung


von Rudi (Gast)


Lesenswert?

hi,
wie kann ich am schnellsten einen Integer Wert in einen String 
konvertieren?

von Peter (Gast)


Lesenswert?

Müsste in jedem Programmierhandbuch für C zu finden sein: itoa()

_______________________________________

char* itoa (int __val, char * __s, int __radix)

Convert an integer to a string.
The function itoa() converts the integer value from val into an ASCII 
representation that will be stored under s. The caller is responsible 
for providing sufficient storage in s.

Note:
The minimal size of the buffer s depends on the choice of radix. For 
example, if the radix is 2 (binary), you need to supply a buffer with a 
minimal length of 8 * sizeof (int) + 1 characters, i.e. one character 
for each bit plus one for the string terminator. Using a larger radix 
will require a smaller minimal buffer size.

Warning:
If the buffer is too small, you risk a buffer overflow. Conversion is 
done using the radix as base, which may be a number between 2 (binary 
conversion) and up to 36. If radix is greater than 10, the next digit 
after
’9’ will be the letter ’a’.

If radix is 10 and val is negative, a minus sign will be prepended. The 
itoa() function returns the pointer passed as s.

von Karl H. (kbuchegg)


Lesenswert?


von Luther B. (luther-blissett)


Lesenswert?

Karl heinz Buchegger wrote:
> 
http://www.mikrocontroller.net/articles/FAQ#Wie_kann_ich_Zahlen_auf_LCD.2FUART_ausgeben.3F

Oha. die ItoA ist kaputt. Ich erlaube mir mal das zu korrigieren.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.