I have:
char *str = "abc def abcdef ghi xyz";
I want to assign
const char *a = "abc";
const char *b = "def";
const char *c = "abcdef";
const char *d = "ghi";
const char *e = "xyz";
Key here is that number of spaces can be more than one.
Please suggest an efficient way.
Efficency is in the eye of the beholder. But take a look at strtok; however, you will need to work with a copy of the string that can be modified.
Note that char *str = "blah" is not a good idea. You should be using const char *str = "blah".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With