I have a function that takes char * as one of its parameters. I need to manipulate it, but leave the original char * intact. Essentially, I want to create a working copy of this char *. It seems to be easy, but I'm really struggling.
My first (naive) attempt was to create another char * and set it equal to the original:
char* linkCopy = link;
This does not work, of course, because all I did was get them to point to the same place.
Should I use strncpy to accomplish this?
I tried the following, but it fails:
char linkCopy[sizeof(link)] = strncpy(linkCopy, link, sizeof(link));
Did I miss something obvious ...?
EDIT: My apologies, I tried to simplify the examples, but I left some of the longer variable names in the second example. Fixed.
c string
Tim
source share