Hi all,
Suppose If I ve string1="/a/b/c"
I want to remove /c from string1.
Which function I will use here??
Thanks
Hi all,
Suppose If I ve string1="/a/b/c"
I want to remove /c from string1.
Which function I will use here??
Thanks
if the substring you want to remove is at the end of the string, just put a 0 at the beginning of the string you want removed. If the substring is somewhere in the middle, then use strcpy() to move the remainder of the string over the top of the substring you want removed. In both cases the string must be writable, that is, it can't be a string literal.
Hi
You can write your own function for this purpose! But first of all you have to be carefuk about your string initialization. In Linux environment char *string="something" is considered as a string constant and you will get a SIGSEGV if you try to change the string content. On the other hand, while programming in ancient MSDOS (not in windows, I have never tried this in windows!) you don't get such an error!.
Use strstr() in order to find the sub-string and perform a strcpy(). Reading the man pages may help you...
http://man.linuxquestions.org/?query...ction=0&type=2
http://man.linuxquestions.org/?query...ction=0&type=2
Hope helps...
Code:char string1[] = "/a/b/c"; char *p = strstr(string1, "/c"); *p = 0;
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Thanks a lot!!!
I really appreaciate your suggestion!!
Palku