0

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.

4
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by Dave Sinkula
Featured Replies
  • [QUOTE=Iam3R;1131434][CODE] char str[]="the quick brown fox and the lazy dog" ; int i =0; while(str[i] !=' ' ) i++; strcpy(str,str+i+1); [/CODE] works if the above is your requirement, analyze it yourself. happy learning...........[/QUOTE] Spot the undefined behavior in the above code. Happy learning! ;) Read More

  • [CODE]strcpy(str,str+i+1);[/CODE] [QUOTE]The strcpy function copies the string pointed to by s2 (including the terminating null character) into the array pointed to by s1. [COLOR="Red"]If copying takes place between objects that overlap, the behavior is undefined.[/COLOR][/QUOTE] Read More

0

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...........

1
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 by Dave Sinkula: Added emoticon.

Comments
Nice :)
0

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.

1
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 by Dave Sinkula: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.