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


Groups > comp.lang.c > #69136

Re: Program to print a pattern of hashtags: issues with spaces

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: Program to print a pattern of hashtags: issues with spaces
Date 2015-09-03 16:10 +0100
Organization A noiseless patient Spider
Message-ID <87egifh737.fsf@bsb.me.uk> (permalink)
References <2ba87e0d-d563-4890-9e8f-a8a64916f266@googlegroups.com> <874mjdj7zx.fsf@bsb.me.uk> <fe38ea5f-8ad7-4546-bba2-d1f59fae6031@googlegroups.com>

Show all headers | View raw


Alla _ <modelling.data@gmail.com> writes:
<snip>
> Thank you very much. This is a amazing.
> I am trying to compile it (with little changes,
> because Terminal doesn't accept for (int =..)),

Because your book uses C99 I thought you'd know how to compile a C99
program!  You probably just need to use gcc -std=c99 ... but you might
like to know that I use

  gcc -std=c99 -D_ANSI_SOURCE -pedantic -Wall -Wextra
      -Wformat-nonliteral -Wcast-align -Wbad-function-cast
      -Wstrict-prototypes -Winline -Wundef -Wcast-qual -Wshadow
      -Wconversion -ffloat-store -fno-diagnostics-show-option

in order to get lots of helpful warnings (some of which I ignore once I
know that they are OK).

> but I receive a few error messages, which 
> I still don't know how to decipher.
> Here is the program:

You changed the order of the code and forgot the semi-colons after the
function declarations.  That's all.  It's a shame that a simple missing
';' gives such a confusing error but that is sadly very common.

> #include <stdio.h>
>
> void repeat(int n, char c)
>
> void output_line(int i, int length)

You need ; after each of these.  You book puts declarations like this
inside the function that use them.  Doing that would be fun just to see
the responses you'd get here!

> int main(void)
> {
>     int pattern_size, i;
>     if (scanf("%d", &pattern_size) == 1)
>     {

Yo could put "int i;" here.  I would if I were forced to use old C.

>         for (i = 0; i < pattern_size; i++)
>             output_line(i, pattern_size);
>     }

You should be consistent with your chosen brace style (the placement of
{}s).  I don't like to use redundant ones, but if you add some, you
should add them all -- i.e put {}s round the body of the for statement
as well.

> }
> void repeat(int n, char c)
> {
>     int i;
>     
>     for (i = 0; i < n; i++)
>         putchar(c);
> }

And again here.

<snip>
-- 
Ben.

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


Thread

Program to print a pattern of hashtags: issues with spaces Alla _ <modelling.data@gmail.com> - 2015-09-02 04:38 -0700
  Re: Program to print a pattern of hashtags: issues with spaces Richard Heathfield <rjh@cpax.org.uk> - 2015-09-02 13:12 +0100
    Re: Program to print a pattern of hashtags: issues with spaces Gareth Owen <gwowen@gmail.com> - 2015-09-02 20:25 +0100
    Re: Program to print a pattern of hashtags: issues with spaces Keith Thompson <kst-u@mib.org> - 2015-09-02 15:50 -0700
      Re: Program to print a pattern of hashtags: issues with spaces Alla _ <modelling.data@gmail.com> - 2015-09-03 02:07 -0700
      Re: Program to print a pattern of hashtags: issues with spaces Alla _ <modelling.data@gmail.com> - 2015-09-03 02:08 -0700
    Re: Program to print a pattern of hashtags: issues with spaces Alla _ <modelling.data@gmail.com> - 2015-09-03 00:26 -0700
      Re: Program to print a pattern of hashtags: issues with spaces Richard Heathfield <rjh@cpax.org.uk> - 2015-09-03 09:16 +0100
        Re: Program to print a pattern of hashtags: issues with spaces Alla _ <modelling.data@gmail.com> - 2015-09-05 04:35 -0700
          Re: Program to print a pattern of hashtags: issues with spaces Richard Heathfield <rjh@cpax.org.uk> - 2015-09-05 13:08 +0100
            Re: Program to print a pattern of hashtags: issues with spaces Alla _ <modelling.data@gmail.com> - 2015-09-05 05:48 -0700
          Re: Program to print a pattern of hashtags: issues with spaces Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-05 14:56 +0100
        Re: Program to print a pattern of hashtags: issues with spaces Alla _ <modelling.data@gmail.com> - 2015-09-05 05:46 -0700
          Re: Program to print a pattern of hashtags: issues with spaces Richard Heathfield <rjh@cpax.org.uk> - 2015-09-05 14:03 +0100
            Re: Program to print a pattern of hashtags: issues with spaces Alla _ <modelling.data@gmail.com> - 2015-09-05 08:55 -0700
  Re: Program to print a pattern of hashtags: issues with spaces bartekltg <bartekltg@gmail.com> - 2015-09-02 14:39 +0200
  Re: Program to print a pattern of hashtags: issues with spaces Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-02 13:55 +0100
    Re: Program to print a pattern of hashtags: issues with spaces Alla _ <modelling.data@gmail.com> - 2015-09-03 01:51 -0700
      Re: Program to print a pattern of hashtags: issues with spaces Richard Heathfield <rjh@cpax.org.uk> - 2015-09-03 10:01 +0100
        Re: Program to print a pattern of hashtags: issues with spaces Alla _ <modelling.data@gmail.com> - 2015-09-03 02:10 -0700
      Re: Program to print a pattern of hashtags: issues with spaces Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-03 16:10 +0100
      Re: Program to print a pattern of hashtags: issues with spaces Keith Thompson <kst-u@mib.org> - 2015-09-03 09:12 -0700
  Re: Program to print a pattern of hashtags: issues with spaces Barry Schwarz <schwarzb@dqel.com> - 2015-09-02 11:52 -0700
    Re: Program to print a pattern of hashtags: issues with spaces Richard Heathfield <rjh@cpax.org.uk> - 2015-09-02 20:24 +0100
      Re: Program to print a pattern of hashtags: issues with spaces Alla _ <modelling.data@gmail.com> - 2015-09-03 02:06 -0700
        Re: Program to print a pattern of hashtags: issues with spaces Richard Heathfield <rjh@cpax.org.uk> - 2015-09-03 10:36 +0100
          Re: Program to print a pattern of hashtags: issues with spaces Alla _ <modelling.data@gmail.com> - 2015-09-03 03:10 -0700
      Re: Program to print a pattern of hashtags: issues with spaces Tim Rentsch <txr@alumni.caltech.edu> - 2015-09-06 13:45 -0700
    Re: Program to print a pattern of hashtags: issues with spaces Alla _ <modelling.data@gmail.com> - 2015-09-03 02:04 -0700
  Re: Program to print a pattern of hashtags: issues with spaces Alla _ <modelling.data@gmail.com> - 2015-09-03 00:31 -0700
  Re: Program to print a pattern of hashtags: issues with spaces Alla _ <modelling.data@gmail.com> - 2015-09-03 00:49 -0700
    Re: Program to print a pattern of hashtags: issues with spaces Richard Heathfield <rjh@cpax.org.uk> - 2015-09-03 09:23 +0100
      Re: Program to print a pattern of hashtags: issues with spaces Alla _ <modelling.data@gmail.com> - 2015-09-03 02:33 -0700
        Re: Program to print a pattern of hashtags: issues with spaces Richard Heathfield <rjh@cpax.org.uk> - 2015-09-03 10:39 +0100
          Re: Program to print a pattern of hashtags: issues with spaces Alla _ <modelling.data@gmail.com> - 2015-09-03 03:11 -0700
  Re: Program to print a pattern of hashtags: issues with spaces Alla _ <modelling.data@gmail.com> - 2015-09-05 04:40 -0700

csiph-web