0

I'm trying to strip only path from a c string

char *path = "~/folder/sometext.txt"

so I would get only "~/folder/"

Anyone got a hint on how to achieve this? I was thinking of something similar to std::string find_last_of
so I could just indicate the last "/" or "\" in the string and then anything that comes after that will
be removed from the string. But I'm writing this in c only so c++ solutions are not an option.

2
Contributors
2
Replies
9
Views
4 Years
Discussion Span
Last Post by enkitosh
0

Check out strrchr; it will return a pointer to the last char you passed on to this function. You can then strip off that part from path.

0

Nice this is exactly what I was looking for, thank you MonsieurPointer!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.