I get an input with a constant formation. in example:
char* str = "mv /Folder1/folder 2/f1 /Folder1/folder 3"
I need to split it so that i'll end up with two separated string,
str1 == /Folder1/folder 2/f1
str2 == /Folder1/folder 3
I have tried using strtok(str, " /") but it won't work. It ignores the space in the delimiter and only using "/".
Any ideas?
Thank you very much!
Here is a brief explanation of strtok. When you pass " /" you are telling strtok to split on either a "/" or a " ". In fact, strtok will probably not easily suit your needs since it will not use a pair of chars to split, but will use each char to split. You'll then have to provide logic to reassemble split items that go together but have a space in them. You might be able to do so by looking for the empty token caused by having back to back split chars in " /". That would tell you that you are at the start of a new path string. However, that solution won't be very robust since someone could put in double spaces after mv and break it. Most tools require you to use outer delimiters such as quotes or use "\ " for the space that is part of the filename and path.