I have this part in a code:
char* data="My name is: ";
I would like to add to this the argv[1] argument with represents a name. How to do this in c code? I’ve tried strcpy and strcat but i have segmentation fault when Ipcp do this:
strcpy(data,argv[1]);
Can anyone please help?
Also why this: data=data+argv[1] is not working?
You need to provide some memory, where the result of the concatentation can be stored into. For example:
Note, however, that this is error prone: if the value of
argv[1]combined with the prefix string is longer than 1024 characters, this produces a buffer overflow. So, maybe something like this: