Ascii function

Cole

Newbie
Joined
Jan 19, 2004
Messages
6,430
Reaction score
1
Quick question, is there a C++ function for taking a number and outputting the corresponding Ascii letter into a buffer?
 
not that I know of, other than manually looping through all the charachters.

EDIT: if you're just trying to convert an ascii character to a value or vice versa chars and ints are interchangable in C++. If you just save the int to a char it will become the char value and vice versa.
 
I suppose using 10 "if" statements is not an option? thats the only way I could do it :)
 
10 if statements? Try about 90 some lol. I was oringally gonna do it as a switch.

If you just save the int to a char it will become the char value and vice versa.
That almost works. This is for a C++ dll. I need to pass back a string into my C# program. Now it doesn't seem to convert it to an Ascii except if I return it and on my C# program when I set up the function I use char. Except that with char I can only pass one piece of data.

I could set it up so on my C# program I use a while statement but I'd rather not considering this dll isn't just for me to use. I'd rather keep it simple.

Else im looking at 90+ switch. Although I did just write something using this in about...1 minute that generated all 90 for me lol.
 
doesn't itoa just make lets say the int 1770 a string 1770?
I was thinking of a function that convereted:
32 to a space
33 to a !
34 to a \
35 to a #
36 to a $
etc...

Anyway I really don't need it anymore I just wrote some code that outputted everything for me then I copied and pasted it into my program.
 
oh. Just cast it to a char then...
Code:
char c = 32;
cout<<"c= "<<c;
 
ints and chars are interchangable (well, char is one byte, int is four bytes, but that's irrelevant for your question).

characters are stored as ascii values.

so, you don't really need to convert 32 to space; it already is, just use it as a char.

Code:
int asciiCode = 32;
char myChar = asciiCode;

It's probably better to use a cast
Code:
int asciiCode = 32;
char myChar = (char)asciiCode;
 
Yeah I got it. Im so use to working with C# and I wasn't use to the fact that you have to use strncat or strncat_s in order to add to a string. That kind of screwed everything up and I came here. I new from others about int and chars but I couldn't get it to work lol because it kept on giving me "You can't add two pointers".

Anyway my code ended up like this:

while(databyte[a + b] != 0)
{
char temp[1]; temp[0] = databyte[a + b];
strncat_s (builtstring, temp, 1);
a++;
}

This is basically a dll for my C# application. A good sized one to that im documenting and releasing to the public of the Starcraft community. I'm keeping it fully compatible with C# in order to try and get more of the Starcraft Mapping Community involved with making programs for mapping by getting them into a language like C#. This is also for my own program in C#.
 
Back
Top