Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: writing a c program to substitute text Date: Mon, 27 Feb 2017 09:10:16 -0800 Organization: None to speak of Lines: 36 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="704c5d663da9e0150365451e4cbc43e2"; logging-data="30365"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+4JvyYEkC0Er1CRbyT9ARZ" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:BzV/KTt8E1mSgEDmaeGqxl6x1wE= sha1:j10jkYLOZw5o5AblXqYls5dI0/o= Xref: csiph.com comp.lang.c:104892 jt@toerring.de (Jens Thoms Toerring) writes: [...] > A const char * like this is a special case: > > const char * txt = "bar"; > > Is a pointer to an array of chars that resides (often in > write-only) memory and that is ininitialized ith the four > chars 'b', 'a', 'r' and '\0'. I'm pretty sure you meant "read-only", not "write-only". [...] > char * mycat(const char * a, const char *b) [...] > > Note first that this function takes two arguments that are > of type const char *. This does not imply that both the > arguments have to be const char pointers, it could also be > pointers to modifiable arrays (or arrays of allocated memory > as returned by this function). Note second that it's the > responsibility of the caller to make sure that both are > strings, i.e. pointers to char arrays that contain a '\0'. Correction: it's the responsibility of the caller to make sure that both are *pointers to* strings. (A "pointer to a string" is by definition a pointer to the initial character of a string.) [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"