Thread: how to properly indent and format a source code?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2010
    Location
    Europe
    Posts
    87

    how to properly indent and format a source code?

    Hello.

    I want to learn how to indent and format properly my source codes. I have found this online:

    https://en.wikipedia.org/wiki/Indent_style
    GNU Coding Standards: Formatting

    Here is a source code that I wrote where I was criticized that it is not correctly formated:

    why this code is not working? i wanted to multiply a matrix by itself

    Code:
    #include <stdio.h>
      
    int main()
    {
        int i,j;
        int array1[3][3]= {{0,0,0},{0,12,36},{0,32,56}} ;
        int sqr[3][3];
     
        /* multiplication part */
        for(i=0;i<3;i++)
        {
               for(j=0;j<3;j++){
                                  sqr[i][j]=array1[i][0]*array1[0][j]+array1[i][1]*array1[1][j]+array1[i][2]*array1[2][j];
                               }
        }
     
     
     
        /* here is the printing part */
        for(i=0;i<3;i++)
        {
            for(j=0;j<3;j++){
                            printf("%d\t",sqr[i][j]);
                            }
            printf("\n");
        }
        return 0;
    }
    1) What does it mean to properly indent a code? >> I think that this is pretty clearly explained in the wikipedia article and I think that I already do that right, even in the example

    2) What does it mean to properly indent a code? >> Does it mean two empty lines between code? What more?

    Thank you.

    A corrected version:

    Code:
    #include <stdio.h>
      
    int main()
    {
        int i,j;
        int array1[3][3]= {{0,0,0},{0,12,36},{0,32,56}} ;
        int sqr[3][3];
     
    
        /* multiplication part */
        for(i=0;i<3;i++)
        {
            for(j=0;j<3;j++){
                               sqr[i][j]=array1[i][0]*array1[0][j]+array1[i][1]*array1[1][j]+array1[i][2]*array1[2][j];
                            }
        }
    
    
        /* here is the printing part */
        for(i=0;i<3;i++)
        {
            for(j=0;j<3;j++){
                            printf("%d\t",sqr[i][j]);
                            }
            printf("\n");
        }
    
    
        return 0;
    }
    Last edited by nerio; 02-05-2016 at 09:46 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code not working properly.
    By iiwii in forum C Programming
    Replies: 16
    Last Post: 06-18-2015, 10:38 PM
  2. Code not functioning properly
    By mgravier in forum C Programming
    Replies: 5
    Last Post: 03-20-2013, 06:16 PM
  3. how to properly call an executable from C code?
    By remy06 in forum C Programming
    Replies: 3
    Last Post: 05-14-2009, 03:48 AM
  4. how to properly comment on c code
    By agentsmith in forum C Programming
    Replies: 15
    Last Post: 01-30-2008, 01:13 PM
  5. Convert source to HTML format
    By bobk544 in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 07-06-2006, 07:40 PM