Hey
i was wondering if theres a way to add a single character to a char* Variable.
Hey
i was wondering if theres a way to add a single character to a char* Variable.
There are many ways.
1. Make a short string from your char, and call strcat.
char s[2]; s[0]=ch; s[1]='\0';
kind of thing
2. find the end (strchr or strlen) and append the char yourself, but don't forget to also append a \0
Thanks For The replily but it didnt realy help me the ponit of understanding how i would do it
say i have
char* bla;
and
char bla2;
and i want to add chr bla2 onto the end of bla
any ideas?
Assuming you know that the size of blah2 is small enough to fit within bla, then you could use the strcat function.
Code:strcat(bla, blah2);
This will do what you want:
Code:char *temp = &bla[strlen(bla)]; *temp++ = bla2; *temp = '\0';