cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
UNIX/Linux Programming
Get all strings until the last occurrenc
Get all strings until the last occurrence of a certain character.
Sep 17, 2013 at 8:46pm UTC
umitkarabiyik
(2)
Hi All,
Is there a fast way in C to get all string until last occurrence of a certain character. for example I have string:
'home/user/dir/file.txt'
I want the result (until last .):
'home/user/dir/file'
Here number of slash is dynamic also file name might be in any legal format ( including special chars and white space).
Thanks in advance,
Umit
Last edited on
Sep 17, 2013 at 8:46pm UTC
Sep 18, 2013 at 4:05pm UTC
umitkarabiyik
(2)
I found my answer. Thanks!!!!
In case someone may need
char * pch;
char full_path[100];
char pathWoExt[100]; // path without extention
pch = strrchr(full_path,'.'); // finds last occurrence of .
/* partial copy until specified char which is . in this case */
strncpy ( str3, full_path, pch-full_path);
str3[pch-full_path] = '\0'; /* null character manually added */
puts(str3);
Sep 18, 2013 at 4:07pm UTC
closed account (
Dy7SLyTq
)
why not use c++ with <string>?
Topic archived. No new replies allowed.