>strcat('#',check);
That still won't work.
>I'm just trying to add and # at the begining if there isnt one.
Using C-style strings you prety much have no choice but to use a temporary and do things manually:
Code:
void
purge(
char *check
)
{
if (*check != '#') {
char *save = new char[strlen(check) + 2];
strcpy(save, "#");
strcat(save, check);
strcpy(check, save);
delete [] save;
}
}
Using your function declaration, it doesn't really get better. The above function is dangerous and bug riddled, and you should avoid it if possible. If you can switch to C++ strings, things become much easier:
Code:
void
purge(
string& check
)
{
if (check[0] != '#') {
check = '#' + check;
}
}
Or you'll just have to add parameters to the function so that the C solution can be made more safe:
Code:
void
purge(
char *check,
size_t size
)
{
if (*check != '#') {
if (strlen(check) + 1 >= size) {
throw "Error";
}
char *save = new char[strlen(check) + 2];
strcpy(save, "#");
strcat(save, check);
strcpy(check, save);
delete [] save;
}
}
And so on...