Re: embedded questions!!!




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


.



Relevant Pages

  • Re: Simple string matching exercise
    ... str1 has type pointer to char. ... address returned by malloc) with the address of the string literal. ... Each pointer is incremented during the evaluation of the while. ... - at some point before the next sequence point, increment ...
    (comp.lang.c)
  • Re: Various newbie DeskLib questions
    ... That declares a pointer variable. ... That alters p to point to the first byte of that string. ... but each declaration is independent. ... and, since it's also an array, you get automatic allocation and deallocation, ...
    (comp.sys.acorn.programmer)
  • Re: difference between a pointer array and a stack array?
    ... pointer. ... The expression str1 is converted to an expression that has type char*. ... The sample code, if the ... and I missed the other declaration that appeared at the bottom ...
    (comp.lang.c)
  • Re: segmentation fault
    ... char s; ... it serves to temporarily replace the declaration ... While fgets returns a null string, ... You shouldn't try to printf a NULL pointer. ...
    (comp.lang.c)
  • Re: argument passing question
    ... My declaration in VB: ... ByRef sqlStr As String, ByVal strmlen As Integer) As Integer ... ByVal takes on a different "meaning" when calling external functions in a DLL. ... a BSTR is a long pointer to an allocated memory structure containing a Unicode character string and a 32- bit integer prefix that stores the length of the string. ...
    (microsoft.public.vb.general.discussion)