🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #124

Re: convert *char to string

#124
From: Rich Churcher
Date: Sat, 15 Jan 2000 00:00
21 lines
1411 bytes
Maciej Arciuch <macar@gry.koti.com.pl> writes:

> hi, i am a beginner, but i think i can help you.
> 
> create a pointer:
> 
> char *name = "string_here"
> 
> now you can access each character using name[i], where i is number of
> char you want read/change.

Read, yes.  Change, no.  You've got a pointer addressing an area of
memory populated by a string literal - attempting to alter this is
undefined behaviour in C and C++.  If you need to change something,
use:

  char name[] = "string_here";

-- 
Cheers,  // The alt.comp.lang.learn.c-c++ FAQ:
Rich.    // http://www.raos.demon.co.uk/acllc-c++/faq.html
Technical Details
Message-ID: <m2aem8s527.fsf@mpx.com.au>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <387ed1c7@grissom> <387F81D6.43AE3CAF@gry.koti.com.pl>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109fba,9c3f098f257151c0
X-Google-Attributes: gid109fba,public
X-Google-Thread: 114592,9c3f098f257151c0
X-Google-Attributes: gid114592,public
X-Google-Thread: 10d4ba,9c3f098f257151c0
X-Google-Attributes: gid10d4ba,public
From: Rich Churcher <churchmouse@mpx.com.au>
Subject: Re: convert *char to string
Date: 2000/01/15
Message-ID: <m2aem8s527.fsf@mpx.com.au>
X-Deja-AN: 572734619
References: <387ed1c7@grissom> <387F81D6.43AE3CAF@gry.koti.com.pl>
X-Complaints-To: abuse@mpx.com.au
X-Trace: news1.mpx.com.au 947886266 11124 198.142.208.204 (14 Jan 2000 21:44:26 GMT)
Organization: Optus Internet
NNTP-Posting-Date: 14 Jan 2000 21:44:26 GMT
Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++