Path: csiph.com!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 11:40:02 -0800 Organization: None to speak of Lines: 24 Message-ID: References: <87a897u6b2.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="704c5d663da9e0150365451e4cbc43e2"; logging-data="9869"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/dU02+6eqrQDQuvy2ZZfyM" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:z8G8gj05hzSEdKVnfDUbkEVBQtE= sha1:dictyzaMJdL3IJt5G3NndqJvpsA= Xref: csiph.com comp.lang.c:104919 scott@slp53.sl.home (Scott Lurndal) writes: > BartC writes: >>On 27/02/2017 17:12, Scott Lurndal wrote: >>> BartC writes: [...] >>>> Here's pretty much the same thing but without a VLA, nor the weird thing >>>> with putting an snprintf call inside the array bounds. >>> >>> That weird thing ensures that 'name1' is allocated enough >>> memory to hold the entire string. >> >>But requiring two passes. > > The nature of strings, in C, where there is no associated > length kept (contrast with counted ASCII or VAX-11 descriptors). Even with counted strings, you still have to allocate memory to hold the characters. -- 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"