string & array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hans Van den Eynden

    string & array

    Hallo

    Why isn't this working??

    char *p="abcd";
    p[3]='h';

    I want to replace a character in the p string.

    thx
  • Victor Bazarov

    #2
    Re: string & array

    Hans Van den Eynden wrote:[color=blue]
    > Hallo
    >
    > Why isn't this working??
    >
    > char *p="abcd";
    > p[3]='h';
    >
    > I want to replace a character in the p string.[/color]

    "abcd" has the type 'const char[5]'. You cannot change the value
    of a constant char. You probably want to declare 'p' as an array
    instead of a pointer:

    char p[] = "abcd";
    p[3] = 'h';

    V

    Comment

    Working...