C - How to put a specific arbitrary part of a string into it's own string?
So if I'm given a location of a file like:
/something/somethingelse/thefile.html or /different/moredifferent/otherfile.jpg How can I just take the type of the file at the end? I know I can use strrchr() for a period to get the pointer to the period just before file type. Is there a build in string function that will just take the rest of the string from a certain point on forward in the string? I know it wouldn't be much work to make it myself, but I figured I would find out if it already existed before doing it. Thanks! |
too simpe for the special function
Code:
char str[]="/something/somethingelse/thefile.html"; |
Great great, thanks thanks.
|
and how well will that scheme work if char str[]="/some.thing/some.thing.else/thefile.html"; ?
Best way it to use pointers and scan backward through the string to find the last period in it. |
Quote:
Quote:
|
Oops. I missed the extra "r" in the middle of the function. :D
|
OP - if you have your solution, please mark query as SOLVED.
|
Oops, sorry about not marking solved. I usually remember that.
|
Quote:
"/foo/.baz" "./foo" "/foo.causeBufferOverFlow" Marking threads as solved is wrong, especially since the person who marks it as such does not have the knowledge to know if there are problems. I will purposely leave this as an exercise. |
Whilst i understand your point dmail, I also cannot tell if the OP understands that the solution is not final but may need
some more work just as it may be all they need to solve this particular issue. But as OPs last post was: Quote:
|
All times are GMT -5. The time now is 02:10 AM. |