I was wondering how you could take 1 string, split it into 2 with a delimiter, such as space, and assign the 2 parts to 2 separate strings. I\'ve tried using strtok()
If you have a char array allocated you can simply put a '\0'
wherever you want.
Then point a new char * pointer to the location just after the newly inserted '\0'
.
This will destroy your original string though depending on where you put the '\0'
If you're open to changing the original string, you can simply replace the delimiter with \0
. The original pointer will point to the first string and the pointer to the character after the delimiter will point to the second string. The good thing is you can use both pointers at the same time without allocating any new string buffers.