How to split a string to 2 strings in C

前端 未结 8 633
猫巷女王i
猫巷女王i 2020-11-28 04:29

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()

8条回答
  •  眼角桃花
    2020-11-28 05:30

    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'

提交回复
热议问题