Re: split a /path/filename into components



Rikishi 42 wrote:
Eric wrote:


Is there a C library function that can take a path and break it into its
component parts? I think dos has one called fnsplit but i cant seem to
find an equal in the linux world


I'm working with Python mostly lately, so memory isn't fresh...

But wasn't there a strtok() function in C, that would split a string, based
on a given char ? Us '/' as that char, and you should be fine.

The strtok function has too many problems to be really usefull.
From the manual page:

Never use these functions. If you do, note that:

These functions modify their first argument.

These functions cannot be used on constant strings.

The identity of the delimiting character is lost.

The strtok() function uses a static buffer while parsing, so it's not thread safe. Use strtok_r() if this matters to you.


--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett

.



Relevant Pages

  • Re: problem parsing strings
    ... >> with c/c++, I have again some problems with the usage of strings, ... >> wanted to use the function STRTOK() ... char *endptr; ... they are safe to use with constant strings. ...
    (comp.lang.c)
  • Re: My own fuction: Access Violation error...
    ... Note that strtok is not a particularly well-designed library function, ... for using the obsolete 'char' type to represent text? ... Modern code is always ...
    (microsoft.public.vc.mfc)
  • Re: pointer from integer?
    ... char *p1, *p2; ... You need to research strtok in your reference. ... makes pointer ... Is there a way to get gdb to give more detailed output? ...
    (comp.lang.c)
  • Re: problem with strtok()
    ... It seems that if I make a call to strtok(), then make a call to another function that also makes use of strtok, the original call is somehow confused or upset. ... int tokenize_input(Sale *sale, char *string){ ... rv = strcpy(dest, source); ...
    (comp.lang.c)
  • Re: strtok causes Segmentation fault
    ... Joe Smith wrote: ... When I run the program I get a segmentation fault on the first strtok. ... int createvarible(const int sock, char *name, char *type, char *value, ...
    (comp.lang.c)