[Courses] C Programming For Absolute Beginners, A note about indentation

Leslie leslie.brothers at verizon.net
Mon Mar 12 22:37:35 UTC 2012


On Mon, 2012-03-12 at 11:39 +1100, Jacinta Richardson wrote:

> HOMEWORK: Correct the indentation on one of your previous exercises.
> 
I incorporated some other improvements as well. I replaced multiple
"printf"s with "puts" as advised by C. Howard.
I used Jacinta's hints on printf formatting to condense my code for
aligning numbers on the right side.

//0312test.c

#include <stdio.h>

int main()
{
    int a = 0;
    int total = 0;

    puts ("\n\n"
      "       *******************************************\n"
      "       *                                         *\n"
      "       *         Two-column Table                *\n"
      "       *             by Leslie                   *\n"
      "       *                                         *\n"
      "       *                                         *\n"
      "       *******************************************\n\n"

      " \t\ta\t       total\n"
      "       ___________________________________________\n\n"
      );


    for (a = 1; a <=12; a = a+1)
    {
        total = total + a;
        printf ("\t\t%2i\t\t%2i\n", a, total);
    }
    
    return 0;
}

It seemed to matter that I had an empty line before the 'puts'
statement.  With no empty line after initializing the variables, it
complained upon compiling and wouldn't include the ".eh_frame_hdr table"
when it ran.  But as above, okay.

Thanks for the good hints on indentation.

> _______________________________________________
> Courses mailing list
> Courses at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/courses




More information about the Courses mailing list