Re: embedded questions!!!
- From: "Richard Henry" <rphenry@xxxxxxxx>
- Date: Fri, 13 Jan 2006 07:16:56 -0800
"John B" <spamj_baraclough@xxxxxxxxxxxxxxxxxxx> wrote in message
news:43c7b8d3$0$819$4c56ba96@xxxxxxxxxxxxxxxxxxxxxxxxx
> 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.
Isn't str2 also a pointer?
BTW, I will admit a recurring problem with understanding the nuances of C
pointers.
.
- Follow-Ups:
- Re: embedded questions!!!
- From: Logan Shaw
- Re: embedded questions!!!
- From: Dave Hansen
- Re: embedded questions!!!
- References:
- Re: embedded questions!!!
- From: Rufus V. Smith
- Re: embedded questions!!!
- From: Chuck F.
- Re: embedded questions!!!
- From: John B
- Re: embedded questions!!!
- Prev by Date: Re: Not enough memory to declare global variable.
- 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
|