Re: embedded questions!!!
- From: "John B" <spamj_baraclough@xxxxxxxxxxxxxxxxxxx>
- Date: 13 Jan 2006 14:27:32 GMT
On 12/01/2006 the venerable Chuck F. etched in runes:
> Rufus V. Smith wrote:
> >"#define" <u4karsh@xxxxxxxxx> wrote in message
> > >
> > > Some C questions were bugging me from quite some time. Any answers!
> > > please share.
> > >
> > > 2. Given 2 Strings char *str1 = "JHONSON";
> >> char *str2 = "O";
> > >
> > > what is the fastest way to remove all occurences of letter O
> > > from str1.
> >
> > str1[0] = '\0';
>
> Bzzt - WRONG. str1 contains a pointer to a non-modifiable string (which may well reside in ROM).
> str1 itself contains no letter O. Thus the only way is:
>
> str1 = "JHNSN";
>
> Things would be different if the original declaration was:
>
> char str1[] = "JHONSON";
>
> which would have initialized a character array to a C string.
Bzzzzt - WRONG.
A pointer to non-modifiable string would be declared as
const char *str1 = "JHONSON";
The two declarations:
char str1* = "JHONSON";
and
char str2[] = "JHONSON";
both allocate space for a modifiable string. The difference being that the first one also creates a
pointer to that string.
--
John B
.
- Follow-Ups:
- Re: embedded questions!!!
- From: Jonathan Kirwan
- Re: embedded questions!!!
- From: Chuck F.
- Re: embedded questions!!!
- From: Hans-Bernhard Broeker
- Re: embedded questions!!!
- From: Richard Henry
- Re: embedded questions!!!
- References:
- Re: embedded questions!!!
- From: Rufus V. Smith
- Re: embedded questions!!!
- From: Chuck F.
- Re: embedded questions!!!
- Prev by Date: Re: embedded questions!!!
- Next by Date: Re: Not enough memory to declare global variable.
- Previous by thread: Re: embedded questions!!!
- Next by thread: Re: embedded questions!!!
- Index(es):
Relevant Pages
|