If you just want to change which string literal protoName points to, you just need to change
*protoName = "HOPOPT";
to
protoName = "HOPOPT";
*protoName = tries to write the first character pointed to by protoName . This will not work in your case, since protoName points to a string literal that cannot be changed.
You also need to change your sprintf call to
sprintf(all,"IPv4','%s'", protoName);
The %s format specifier signals that you will pass a pointer to a char array with zero completion. *protoName gives the character code of the first character pointed to by protoName ; sprintf does not know this, so it would process this character code as the address of the array to read from. You do not own this memory, so the effects of reading from it will be undefined; likely to fail.
As an aside, if you have a writable char array and you want to change its contents, you will need to use strcpy to copy a new array of characters into it.
source share