Umwandlung einer Zahl in einen String.

Umwandlung einer Zahl in einen String. Aus der Zahl i wird der String 'i' gemacht.

Name Typ Default Beschreibung
Return char*   Zeiger auf einen statischen String. Das Ergebnis wird bei einem nächsten Aufruf der Funktion überschrieben.
i int - Erstelle eine String-Repräsentation dieser Zahl
char	s[256];
int i	= 1231
strcpy (s, itoa (i+3)); showmessage (s); // 1234

Der Datentyp int ist 64 Bit breit. Hier ein Beispiel mit Zahlen, deren Darstellung mehr als 32 Bit benötigt.

int main ()
{
    int    	a 		= 6917529027641081856;
    char  *	astr	= "6917529027641081856";
wlog ("", "a=%d\t(and as string '%s')\n", a, itoa (a)); wlog ("", "a=0x%x\t(and as string '%s')\n", a, itoa (a)); wlog ("", "astr='%s'\t(and as int %d)\n", astr, val (astr)); wlog ("", "astr='%s'\t(and as int 0x%x)\n", astr, val (astr));
wlog ("", "string compare : a ?= astr : %d\n", (a == val (astr))); wlog ("", "int compare : a ?= astr : %d\n", strcmp (itoa (a), astr)==0);
return 0; } // Ausgabe // //a=6917529027641081856 (and as string '6917529027641081856') //a=0x6000000000000000 (and as string '6917529027641081856') //astr='6917529027641081856' (and as int 6917529027641081856) //astr='6917529027641081856' (and as int 0x6000000000000000) //string compare : a ?= astr : 1 //int compare : a ?= astr : 1

Das obige Beispiel funktioniert natürlich auch dann, wenn die Zahlen als Hex-Zahlen definiert werden.

int main ()
{
    int    	a 		= 0x6000000000000000;
    char  *	astr	= "0x6000000000000000";
wlog ("", "a=%d\t(and as string '%s')\n", a, itoa (a)); wlog ("", "a=0x%x\t(and as string '%s')\n", a, itoa (a)); wlog ("", "astr='%s'\t(and as int %d)\n", astr, val (astr)); wlog ("", "astr='%s'\t(and as int 0x%x)\n", astr, val (astr));
wlog ("", "string compare : a ?= astr : %d\n", (a == val (astr))); wlog ("", "int compare : a ?= astr : %d\n", strcmp (itoa (a), astr)==0);
return 0; } // Ausgabe // //a=6917529027641081856 (and as string '6917529027641081856') //a=0x6000000000000000 (and as string '6917529027641081856') //astr='0x6000000000000000' (and as int 6917529027641081856) //astr='0x6000000000000000' (and as int 0x6000000000000000) //string compare : a ?= astr : 1 //int compare : a ?= astr : 1

Seit

Verfügbarkeit
priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

Siehe auch
val

Alphabetic index HTML hierarchy of classes or Java