• 19.08.2025, 20:48
  • Register
  • Login
  • You are not logged in.

 

Eumel

God

[C++] ASCII-Code to String/Char

Tuesday, November 18th 2003, 4:09pm

Wie kann ich einen ASCII-Code so umwandeln, dass ein Char daraus wird?

Also, dass aus 67 ein Buchstabe wird.

MfG
"I've always said, the Web is the sum of all human knowledge plus porn.", Ron Gilbert
UltraStar Manager 1.7.2 | Infos zu meinem PC | .o0 DeathSpank 0o.

xx_ElBarto

God

Re: [C++] ASCII-Code to String/Char

Tuesday, November 18th 2003, 4:17pm

direkt umwandeln weiß ich nicht, aber mit printf(variable,%c) kannste es als char ausgeben ;D

Eumel

God

Re: [C++] ASCII-Code to String/Char

Tuesday, November 18th 2003, 4:55pm

Ich will ein eingegebenes Zeichen an einen String ranhängen. Leider bekomme ich bei Tastendruck nur den Scancode bzw. den ASCII-Code.

MfG
"I've always said, the Web is the sum of all human knowledge plus porn.", Ron Gilbert
UltraStar Manager 1.7.2 | Infos zu meinem PC | .o0 DeathSpank 0o.

hurra

God

Re: [C++] ASCII-Code to String/Char

Tuesday, November 18th 2003, 5:17pm

hm:

char text[100];
int eingabe;
text[3]=eingabe;


so?
Cu hurra

Eumel

God

Re: [C++] ASCII-Code to String/Char

Tuesday, November 18th 2003, 5:23pm

Da stehen dann mit text-array Zahlen ... das will ich ja nicht. Da sollen Zeichen stehen, aus dem ASCII-Code heraus.

MfG
"I've always said, the Web is the sum of all human knowledge plus porn.", Ron Gilbert
UltraStar Manager 1.7.2 | Infos zu meinem PC | .o0 DeathSpank 0o.

hurra

God

Re: [C++] ASCII-Code to String/Char

Tuesday, November 18th 2003, 5:31pm

Ich versteh dich ned ??? ???

char text[100];
int eingabe;
text[3]=eingabe-/+48;

Mach mal + oder - 48. Vielleicht ergibt sich dass, was du willst.
Cu hurra

sebastian

Administrator

Re: [C++] ASCII-Code to String/Char

Tuesday, November 18th 2003, 7:29pm

Was willst du?
wenn du schon Daten im ASCII format hast, sprich als 8 bit, dann kannst du die zeichenweise als buchstabe ausgeben.

zb, eine funktion liefert dir
getvalue(unsigned short int ascii);

dann steht in der Variable für ascii eine 8bit zahl.
dann brauchst du nur noch so rechen.
char textarray[10];
textarray[0]=ascii;

Im TextArray[0] steht nun der ascii wert den du mit printf oder sonstwie weitergibst.
War es das was du meintest?

MfG
Sebastian

Eumel

God

Re: [C++] ASCII-Code to String/Char

Tuesday, November 18th 2003, 7:53pm

Ne funzt nicht. Ich bekomme immer nur ne Zahl in den String rein.

MfG
"I've always said, the Web is the sum of all human knowledge plus porn.", Ron Gilbert
UltraStar Manager 1.7.2 | Infos zu meinem PC | .o0 DeathSpank 0o.

sebastian

Administrator

Re: [C++] ASCII-Code to String/Char

Tuesday, November 18th 2003, 8:06pm

wenn ich dich jetzt ricchtig verstanden habe willst du aus einer ZAHL zb. int ein string machen.
geht so:

char textbuffer[30]
int zahl=30;

sprintf(textbuffer, "%d", zahl);

den in dem string steht jetzt nullteminiert die variable zahl als string.

Sebastian

EDIT: poste mal ein teil vom quellcode

Eumel

God

Re: [C++] ASCII-Code to String/Char

Wednesday, November 19th 2003, 5:38pm

Genau DAS will ich nicht :D

Source code

1
2
int a;
a = readkey() >> 8;


In Variable a steht jetzt der ASCII-Code einer Taste, welche bei "readkey" gedrückt wurde.

Bsp: Man drückt das "M". Dann steht in a: 77. Also der ASCII-Code im Dezimalsystem.

Wenn ich jetzt:

Source code

1
2
CString text;
text = text.GetString() + a;


mache, hab ich die Zahl 77 im CString-Objekt "text". Wenn ich jetzt den String ausgeben lasse, erscheint "77". Ich will aber, dass "M" erscheint. Also muss ich irgendwie hinkriegen, dass die Zahl 77 in den Character "M" umgewandelnt wird.

Verstanden? ;D

MfG
"I've always said, the Web is the sum of all human knowledge plus porn.", Ron Gilbert
UltraStar Manager 1.7.2 | Infos zu meinem PC | .o0 DeathSpank 0o.

r1ppch3n

Moderator

Re: [C++] ASCII-Code to String/Char

Wednesday, November 19th 2003, 5:54pm

mach doch aus 'int a' ma 'char a'
akzeptiert ohne weiteres auch zahlen (byte is byte, wofür das byte steht is der variable doch egal ;)) und spuckt bei ausgaben für gewöhnlich buchstaben aus
umrechnungen sind hier nicht wirklich nötig...

Eumel

God

Re: [C++] ASCII-Code to String/Char

Wednesday, November 19th 2003, 9:25pm

aber readkey() gibt eigentlich int zurück.

Hatte ich glaub ich auch schon probiert:

Source code

1
2
3
4
char ch;
CString text;
ch = readkey() & 0xff; // hab hier mal korrigiert
text = ch; // spuckt immer noch ASCII-Code-Zahlen aus


Hmmm.  :-/

MfG
"I've always said, the Web is the sum of all human knowledge plus porn.", Ron Gilbert
UltraStar Manager 1.7.2 | Infos zu meinem PC | .o0 DeathSpank 0o.

Eumel

God

Re: [C++] ASCII-Code to String/Char

Wednesday, November 19th 2003, 10:01pm

Habs hinbekommen! :D :D :D

Source code

1
2
3
4
5
6
7
char buffer[2];
int i;
CString text;

i = readkey() & 0xff;
sprintf(buffer, "%c", (char) i);
text = buffer;


Juhuuu!!!

MfG
"I've always said, the Web is the sum of all human knowledge plus porn.", Ron Gilbert
UltraStar Manager 1.7.2 | Infos zu meinem PC | .o0 DeathSpank 0o.