string & array

  • Thread starter Hans Van den Eynden
  • Start date
H

Hans Van den Eynden

Hallo

Why isn't this working??

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

I want to replace a character in the p string.

thx
 
V

Victor Bazarov

Hans said:
Hallo

Why isn't this working??

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

I want to replace a character in the p string.

"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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,965
Members
47,512
Latest member
FinleyNick

Latest Threads

Top