Ian Collins <ian-> writes:
> On 11/20/10 10:31 AM, Super Ted wrote:
>> Ian Collins writes:
>>
>>> On 11/20/10 09:10 AM, Super Ted wrote:
>>>> #include<stdio.h>
>>>
>>> You haven't included<ctype.h> or<string.h>, so you don't have
>>> prototypes for strcpy, strlen or isspace.
>>
>> Sorry, but adding those includes does not fix the problem!
>
> It should, the code appears fine (and works for me).
>
> ./a.out
> *Hello world*
> (deleted 10 spaces)
strcpy(s,s+1);
C99 7.21.2.3:
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.
If you really wanted to do it this way, you could use memmove(),
which works for overlapping arguments. But the approach
is quite inefficient; each character is copied multiple times.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"