Re: [C] simple string question

From: Alan (alanchoiyimlung_at_sinatown.com)
Date: 02/05/04


Date: Thu, 5 Feb 2004 11:35:56 +0800


"AirPete" wrote:
> Alan wrote:
> > hi all,
> >
> > I want to define a constant length string, say 4
> > then in a function at some time, I want to set the string to a
> > constant value, say a
> > below is my code but it fails
> > what is the correct code?
> > many thx!
> >
> >
> > char string[4] = {0};
> >
> > string = 'a '; /* <-- failed */
>
> memcpy("abcd", string, sizeof(string));

sorry, but it doesn't work
when I run the program, the program crashes

>
> - Pete
>
>



Relevant Pages

  • Re: [C] simple string question
    ... > Alan wrote: ... >> then in a function at some time, I want to set the string to a ... >> what is the correct code? ... the program crashes ...
    (comp.lang.c)
  • Re: [C] simple string question
    ... Alan wrote: ... > I want to define a constant length string, ... > What is the correct code? ... a *string* must be terminated by a nul character '\0'. ...
    (comp.lang.c)
  • Re: [C] simple string question
    ... Alan wrote: ... > I want to define a constant length string, ... > What is the correct code? ... a *string* must be terminated by a nul character '\0'. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: [C] simple string question
    ... Alan wrote: ... > I want to define a constant length string, ... > what is the correct code? ...
    (comp.lang.c)
  • Re: [C] simple string question
    ... Alan wrote: ... > I want to define a constant length string, ... > what is the correct code? ...
    (alt.comp.lang.learn.c-cpp)