double to char???
-
Hi Leute,
gibt es eine Funktion die mir eine double oder int variable in einen String umwandelt?
Ich habe zuvor einen string mit der Funktion "strtod" in eine doublevariable umgwandelt und anschließend mit einer anderen variablen subtrahiert.
Jetzt möchte ich das Ergebnis in eine Datei schreiben, wie kann ich das machen?Gruß
spacehelix
-
Das kannst du z.B. mit snprintf() (schreibt in ein char-Array) oder mit fprintf() (schreibt in einen Stream) machen.
-
char *_ltoa( long value, char *string, int radix );
[msdn]_ltoa[/msdn]
char *_itoa( int value, char *string, int radix );
[msdn]_itoa[/msdn]
radix ist die Basis (also 10 Bei Dezimal, 16 bei Hexadezimal, usw).
-
paddy82 schrieb:
char *_ltoa( long value, char *string, int radix );
Nana, heisst das Forum nicht "ANSI-C"?
-
jupp, sorry hast ja recht.
-
@TactX: Du meinst sprintf();!
char array[10]; double doub=3.2312432; sprintf( array,"%f",doub);
mfg hohesC
-
hohesC schrieb:
@TactX: Du meinst sprintf();!
Willst du mich jetzt verarschen? Ich meine snprintf(). Vor allem, woher willst _du_ wissen was _ich_ meine?
Und zur Übung kannst du ja gleich mal überlegen warum ich snprintf() meine...
-
man snprintf:
BUGS
Because sprintf and vsprintf assume an arbitrarily long string, callers must be careful not to overflow the actual space; this is often impossible to assure. Note that the length of the strings produced is locale-dependent and difficult to predict. Use snprintf and vsnprintf instead (or asprintf and vasprintf).