Autor Beitrag
Roosevelt
ontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 223

Win XP prof. SP2, Win XP Home SP2, Suse 9.2
Delphi 6 Personal, Delphi 2005
BeitragVerfasst: So 19.03.06 10:50 
In delphi kann man ja über inttostr ein Integer in einen String verwandeln. Gibt es so einen Befehl auch in c? wenn ja wie heißt der?

_________________
Glaube niemals das was du weißt!!!
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: So 19.03.06 10:53 
IntToStr
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: So 19.03.06 11:07 
Hi,

was ist für dich C?

In C gibt es keine Strings, da gibt es nur arrays vom Typ char. Verschiedene Compilerbauer haben da verschiedene Lösungen gefunden. Wenn du z.B. Microsoft Visual C++ mit MFC verwendest hast du die Klasse CString da es aber eine Klasse ist bist du spätestens mit deren Verwendung bei C++ angelangt.

Es währe also hilfreich wenn du uns Zeigen würdest wie du die Stringvariable definierst, welche den konvertierten int aufnehmen soll. Oder geht es nur um die ausgabe? Dann bieter dir auch standard C mit printf eine passende Funktion.

Gruß
Klabautermann
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: So 19.03.06 11:29 
user profile iconKlabautermann hat folgendes geschrieben:
In C gibt es keine Strings, da gibt es nur arrays vom Typ char.
Jain. char* und char[] heißen auch in C "String", wenn sie als String verwendet werden, und nicht als Byte-Array.

Klabautermann hat folgendes geschrieben:
Verschiedene Compilerbauer haben da verschiedene Lösungen gefunden.
In C? Nö.

Klabautermann hat folgendes geschrieben:
Wenn du z.B. Microsoft Visual C++ mit MFC verwendest
Was denn nun? Ich denke es geht um C? Bei C++ ist ein String std::string, bzw std::basic_string<char>. Was irgendwelche Compilerhersteller meinen an zusätzlichen Klassen zurechtzuwursteln ist da erstmal egal, mit std::string ist man zu allem und jedem Kompatibel, auch zu C.

Umwandlung von Integer zu String und umgekehrt in ANSI-C:
ausblenden Quelltext
1:
2:
someinteger = atoi(somecstring); // string -> integer
sprintf(somestringbuffer, "%d", someinteger); // integer -> string
Hat den Nachteil, daß somestringbuffer bereits vor dem Aufruf lang genug sein muss, sonst besteht die Gefahr eines Buffer-Overflows (snprintf() wäre besser, erzwingt aber C99, bei GNU-C würde ich sogar einfach vasprintf() nehmen), aber das ist der ANSI-C-Weg. Einige RTLs bieten vielleicht eine Funktion itoa(), aber das muss nicht so sein.

Umwandlung von Integer zu String und emgekehrt in ISO-C++:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
// Integer -> String
std::ostringstream my_stringstream;
my_stringstream << someinteger;
somestring = my_stringstream.str();

// String -> Integer
std::istringstream my_stringstream(somestring);
my_stringstream >> someinteger;
Ein wenig länger, dafür pures C++ mit allen Vorteilen davon. Aber man kann natürlich auch in C++ die alten ANSI-C-Funktionen aufrufen, man muss lediglich die Strings konvertieren.

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: So 19.03.06 11:38 
Hi,
user profile icontommie-lie hat folgendes geschrieben:
Was denn nun? Ich denke es geht um C?

eben da bin ich mir nicht sicher. Dafür habe ich schon zu oft "C" Fragen gesehen welche sich dann als "my propertary C++" Fragen entpuppten. Aus dem Grund frage ich ja so dumm nach.

Gruß
Klabautermann
Roosevelt Threadstarter
ontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 223

Win XP prof. SP2, Win XP Home SP2, Suse 9.2
Delphi 6 Personal, Delphi 2005
BeitragVerfasst: So 19.03.06 11:42 
also es geht um c und nicht c++ und in c ist ein string ein array auf char.

_________________
Glaube niemals das was du weißt!!!
Stefan.Buchholtz
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 612

WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
BeitragVerfasst: Mo 20.03.06 09:36 
In C heisst die entsprechende Funktion atoi, ist in stdlib.h deklariert.

Stefan

_________________
Ein Computer ohne Windows ist wie eine Schokoladentorte ohne Senf.
Roosevelt Threadstarter
ontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 223

Win XP prof. SP2, Win XP Home SP2, Suse 9.2
Delphi 6 Personal, Delphi 2005
BeitragVerfasst: Mo 20.03.06 19:33 
danke genau danach suchte ich.

_________________
Glaube niemals das was du weißt!!!
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Mo 20.03.06 19:37 
user profile iconRoosevelt hat folgendes geschrieben:
danke genau danach suchte ich.
Genau das (und sogar mehr) habe ich dir schon gestern mittag geschrieben ;-)

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
Roosevelt Threadstarter
ontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 223

Win XP prof. SP2, Win XP Home SP2, Suse 9.2
Delphi 6 Personal, Delphi 2005
BeitragVerfasst: Mo 20.03.06 21:54 
das habe ich aber leider erst nicht verstanden... erst als ich nach dem Befehl von Stefan.Buchholtz gesucht habe.

_________________
Glaube niemals das was du weißt!!!