i am new to C and recently i have a problem with a strcat function.
I have an array of arguments defined like:
#define MAXARGS 10;
char *argvalues[MAXARGS];
All i want is to concatenate the last non-null element of the array with a null terminator. Here is the piece of my code for that:
while (argvalues[i] != NULL) {
if (argvalues[i] == NULL){
strcat(argvalues[i-1], '/0');
printf("i is: %d\n", i);
break;
}
i++;
}
Do you have any idea why segmentation fault happens and is it actually the right way of using strcat?
strcat concatenates two char pointers like so.
pi now holds – hello world
You have to make sure that the destination has enough room for the concatenated result.