Very basic question. I am having problems in converting a char to a char* that points to the actual character. Googling yielded information on strcpy, string, sprintf, etc. After many, many attempts at trying to understand the problem, I still can't get it to work.
I have a character array recv_msg which contains the ASCII values of the characters I need. I need to store the characters (not the values) in a vector msg.
What I have:
std::vector<char> msg;
char recv_msg[max_buffer_length];
...
int i;
for (i=0;i<bytes_transferred;i++) {
msg.push_back(recv_msg[i]);
}
// Problem: when I process my msg I see 49 instead of '1'.
If I do the following as a sanity check, I do get the behavior I need. That is, I see a '5' and not a 53 (ASCII code for 5).
std::vector<char*> msg;
...
int i;
char *val;
for (i=0;i<bytes_transferred;i++) {
msg.push_back(val);
}
// No problem: when I process my msg I see '5' instead of 53.
So I need to turn the ASCII code values (char) into their character representation (char *). How on earth do I do this?
I want to solve the problem at this stage, and not have to do the ASCII -> character conversion when processing the message.
std::stringor would that be too easy?