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: Sun, 26 Feb 2017 13:36:41 -0800 Organization: None to speak of Lines: 31 Message-ID: References: <2c574151-71a0-4bcf-a904-50a13eaf81b0@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="b8cd4aeac47b845ed1638f30cd407196"; logging-data="11570"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/n+VuRiouJqE9nRuEB0SSU" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:ZuTDIAjoexA8h06xY8AoEPeQAHY= sha1:rpaTovlixeWxf0K5hoU9dp8Act8= Xref: csiph.com comp.lang.c:104791 Malcolm McLean writes: > On Sunday, February 26, 2017 at 12:14:23 PM UTC, fred flintstone wrote: >> Let's say that you're hard-coding a string between single quotes, for >> example: >> >> 'arrow' >> >> , how do I declare this string to exist safely? >> >> Do I malloc a 1000 because someone has to make an adult decision? >> > No, you write a function called mystrdup(). (There will also be a strdup > provided with your environment but it may not be available with > certain compiler settings. Malcolm, I'm at a loss to understand how you were able to infer that the OP needs something like strdup. I can't figure out just what he's saying, but my best guess is that const char *s = "arrow"; or const char s[] = "arrow"; would be suitable. I suggest that any speculation beyond that should wait for a more coherent question. [...] -- 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"