ch1maera
ch1maera

Reputation: 1447

Removing First Element in Char * Array Objective C

I have a variable buf stored as char *buf this variable comes out to be an ID that looks something like /3B494538-9120-46E0-95D4-51A4CF5712A1. I want to remove the first element of the char *buf so that /3B494538-9120-46E0-95D4-51A4CF5712A1 becomes 3B494538-9120-46E0-95D4-51A4CF5712A1. How do I do this?

Upvotes: 1

Views: 109

Answers (1)

toma
toma

Reputation: 1469

You can create an array that reuses buf's memory:

char *nonCopyBuf = buf + 1;

or allocate new memory storage:

char *copyBuf = malloc(strlen(buf));
memcpy(copyBuf, buf + 1, strlen(buf));
//...
free(copyBuf);

Upvotes: 4

Related Questions