deleting string...
example:
deleting...

enter string: the quick brown fox and the lazy dog.
enter string to delete: the(the first one)
new string: quick brown fox and the lazy dog.

pls. help me in how to program that...

char str[]="the quick brown fox and the lazy dog" ;
int i =0;
while(str[i] !=' ' )
 i++;
strcpy(str,str+i+1);

works if the above is your requirement, analyze it yourself.
happy learning...........

char str[]="the quick brown fox and the lazy dog" ;
int i =0;
while(str[i] !=' ' )
 i++;
strcpy(str,str+i+1);

works if the above is your requirement, analyze it yourself.
happy learning...........

Spot the undefined behavior in the above code. Happy learning! ;)

Edited 6 Years Ago by Dave Sinkula: Added emoticon.

Comments
Nice :)

Spot the undefined behavior in the above code. Happy learning! ;)

i dint see any undefined behaviour statements in the code.

can you please spot it.

strcpy(str,str+i+1);

The strcpy function copies the string pointed to by s2 (including the terminating null character) into the array pointed to by s1. If copying takes place between objects that overlap, the behavior is undefined.

Edited 6 Years Ago by Dave Sinkula: n/a

This article has been dead for over six months. Start a new discussion instead.