Substring C From String Like Folder1/file1.txt
i have strings like "folder1/file1.txt" or "foldername1/hello.txt" and i need to take the substring that identify the folder name with the slash (/) included
(example: from "folder1/file1.txt" i need "folder1/").
The folders name are not all with the same length. How can i do this in C?? thanks
First, find the position of the slash with strchr:
char * f = "folder/foo.txt"; // or whatever char * pos = strchr( f, '/' );
then copy into a suitable place:
char path; // or whatever strncpy( path, f, (pos - f) + 1 ); path[(pos-f)+1] = 0; // null terminate
You should really write a function to do this, and you need to decide what to do if strchr() returns NULL, indicating the slash is not there.
- → OctoberCMS Backend Loging Hash Error
- → "failed to open stream" error when executing "migrate:make"
- → OctoberCMS - How to make collapsible list default to active only on non-mobile
- → Create plugin that makes objects from model in back-end
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → How to install console for plugin development in October CMS
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → How to update data attribute on Ajax complete
- → October CMS - Conditionally Load a Different Page