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
i have strings like folder1/file1.txt or foldername1/hello.txt and i need to take the substring
Share
First, find the position of the slash with strchr:
then copy into a suitable place:
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.