Re: embedded questions!!!



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
.



Relevant Pages

  • 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: Is C99 the final C? (some suggestions)
    ... >> defined a function that returns an image string for a value of your ... >> need to decide how and whether the user can define precedence for the ... > of declaration. ... "parenthesize, parenthesize, parenthesize". ...
    (comp.lang.c)
  • Re: curious about array initialization.
    ... understanding that its through the variable declaration that we ... By "inline string", I assume you mean a string literal. ... more than that you have implicit storage. ... Its a concept from computer programming. ...
    (comp.lang.c)
  • Re: DhcpRequestParams from dhcpcsvc.dll
    ... it is because I do think that my own vb declaration is wrong, ... string to Unicode with StrConv and pass that as a string. ... Dim sendParams As DHCPAPI_PARAMS ...
    (microsoft.public.vb.winapi)
  • Re: curious about array initialization.
    ... understanding that its through the variable declaration that we ... By "inline string", I assume you mean a string literal. ... more than that you have implicit storage. ...
    (comp.lang.c)