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

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 2016-03-29 09:00 -0700
Organization None to speak of
Message-ID <lntwjp1dgm.fsf@kst-u.example.com> (permalink)
References <4b1ed1df-f855-421f-8a82-82dcab0656e2@googlegroups.com> <832kfbh2q3mn6n0d5vsobentt7gd03d7k8@4ax.com>

Show all headers | 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