Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #85239

Re: Two versions of K&R exercise 3-5: one doesn't print the string

Path csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Two versions of K&R exercise 3-5: one doesn't print the string
Date Tue, 29 Mar 2016 09:00:25 -0700
Organization None to speak of
Lines 30
Message-ID <lntwjp1dgm.fsf@kst-u.example.com> (permalink)
References <4b1ed1df-f855-421f-8a82-82dcab0656e2@googlegroups.com> <832kfbh2q3mn6n0d5vsobentt7gd03d7k8@4ax.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Info mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="3716"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18FSziIEnIKxAKXsSmE+vw8"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
Cancel-Lock sha1:0luHAEnH1bNCgyg8np4D1kA6zR4= sha1:1i9qC05sQygqYUyS4miY2bpJQU0=
Xref csiph.com comp.lang.c:85239

Show key headers only | View raw


Barry Schwarz <schwarzb@dqel.com> writes:
> On Mon, 28 Mar 2016 11:49:16 -0700 (PDT), Alla _
> <modelling.data@gmail.com> wrote:
[...]
>>    if (argc < 3)
>>    {
>>        printf("Usage: ./program, number, base\n");
>
> When using printf to print string like this (either literal, array, or
> pointer), there is a benefit to coding it as
>      printf("%s", your string parameter here);
> This will eliminate any problems if your string should happen to
> contain any '%'.  As you have written it, the '%' would be interpreted
> as the start of a format conversion.

I'd probably put the newline in the format string:

    printf("%s\n", "Usage: ./program, number, base");

Another option (I prefer this one):

    puts("Usage: ./program, number, base");

[...]

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
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"

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Two versions of K&R exercise 3-5: one doesn't print the string Alla _ <modelling.data@gmail.com> - 2016-03-28 11:49 -0700
  Re: Two versions of K&R exercise 3-5: one doesn't print the string Paul N <gw7rib@aol.com> - 2016-03-28 13:42 -0700
    Re: Two versions of K&R exercise 3-5: one doesn't print the string Alla _ <modelling.data@gmail.com> - 2016-03-30 04:01 -0700
  Re: Two versions of K&R exercise 3-5: one doesn't print the string Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-03-28 22:29 +0100
  Re: Two versions of K&R exercise 3-5: one doesn't print the string Barry Schwarz <schwarzb@dqel.com> - 2016-03-28 22:05 -0700
    Re: Two versions of K&R exercise 3-5: one doesn't print the string Jerry Stuckle <jstucklex@attglobal.net> - 2016-03-29 08:49 -0400
    Re: Two versions of K&R exercise 3-5: one doesn't print the string Keith Thompson <kst-u@mib.org> - 2016-03-29 09:00 -0700
      Re: Two versions of K&R exercise 3-5: one doesn't print the string Barry Schwarz <schwarzb@dqel.com> - 2016-03-29 10:42 -0700
        Re: Two versions of K&R exercise 3-5: one doesn't print the string Keith Thompson <kst-u@mib.org> - 2016-03-29 12:12 -0700
  Re: Two versions of K&R exercise 3-5: one doesn't print the string programming109@gmail.com - 2016-04-11 08:29 -0700
    Re: Two versions of K&R exercise 3-5: one doesn't print the string programming109@gmail.com - 2016-04-11 08:35 -0700
    Re: Two versions of K&R exercise 3-5: one doesn't print the string Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-04-11 19:59 +0100
      Re: Two versions of K&R exercise 3-5: one doesn't print the string programming109@gmail.com - 2016-04-11 22:41 -0700
        Re: Two versions of K&R exercise 3-5: one doesn't print the string luser droog <luser.droog@gmail.com> - 2016-04-11 23:18 -0700
        Re: Two versions of K&R exercise 3-5: one doesn't print the string Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-04-12 11:02 +0100
    Re: Two versions of K&R exercise 3-5: one doesn't print the string Keith Thompson <kst-u@mib.org> - 2016-04-12 11:26 -0700

csiph-web