A little suggestion before positing your code

This is a discussion on A little suggestion before positing your code within the C Programming forums, part of the General Programming Boards category; Please format your code before posting! At least it contains good indentations. For example somebody(pssst...) posted this code: Code: #include ...

  1. #1
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489

    A little suggestion before positing your code

    Please format your code before posting! At least it contains good indentations.
    For example somebody(pssst...) posted this code:
    Code:
    #include <stdio.h>
    int main()
    {
    int x,ul,ll,j=1;
    
    printf("Please enter your desired number you want its divisible numbers\n");
    scanf("&#37;i",&x);
    
    
    printf("Please enter the lower limit you desire\n");
    scanf("%i",&ll); //ALERT: getchar(); --> its only with characters!
    
    printf("Please enter the upper limit you desire\n");
    scanf("%i",&ul);
    
    
    	for (j >= ll ; j <= ul; j--)
    	{
    		if (j < x)
    		{
    	if (j % x  == 0)
    			{
    				printf("\n%i", x);
    				j++;
    
    			}
    		}
    		else
    		{       if ( j == x)
    			{
    				j = 0;
    				printf("\t\t");
    			}
    		}
    	}
    
    	return (0);
    }
    ...it should be look like this:
    Code:
    #include <stdio.h>
    
    int main()
    {
       int x, ul, ll, j = 1;
    
       printf("Please enter your desired number you want its divisible numbers\n");
       scanf("%i", &x);
    
       printf("Please enter the lower limit you desire\n");
       scanf("%i", &ll); //ALERT: getchar(); --> its only with characters!
    
       printf("Please enter the upper limit you desire\n");
       scanf("%i", &ul);
    
       for(j>=ll; j<=ul; j--)
       {
          if(j < x)
          {
             if((j % x) == 0)
             {
                printf("\n%i", x);
                j++;
             }
          }
          else
          {
             if(j == x)
             {
                j = 0;
                printf("\t\t");
             }
          }
       }
    
       return(0);
    }
    Which is more readable?
    Please format your code before posting, because it make us easier to analyst your code and its algorithm.
    Last edited by audinue; 07-08-2008 at 05:11 AM.

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,583
    A hint for you:
    Noone reads topics like these before posting. And those who do are smart enough to indent properly anyway.
    That's mostly how it is.

    I keep seeing how members try to help by posting useful information such as this, only trying to help, but in the end, noone reads them O_O
    (Not directed at you for trying to help, just something to keep in mind.)
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    217
    People mix spaces and tabs. Doesn't look nice.

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    IMO, you've made it worse in some cases,

    Code:
    for(j>=ll; j<=ul; j--)
    Whitespace is good, why remove it?

    Code:
    }
    else
    {
    I really don't like that style,

    Code:
    return(0);
    Kinda makes return look like a function.

  5. #5
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    And those who do are smart enough to indent properly anyway.
    Elysia: (T_T")
    zacs7: Style doesn't matter, choose what you like. The important thing is write clear and readable code (mostly by indentations). Just that.
    Last edited by audinue; 07-08-2008 at 08:36 AM.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,709
    Thank you for your concern, but I note that this was pointed out in the stickied thread entitled << !! Posting Code? Read this First !! >>, when I was an unregistered lurker here faithfully writing #include <iostream.h> in my void main() C++ programs.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User PunchOut's Avatar
    Join Date
    Jun 2008
    Location
    norfolk, va
    Posts
    16
    Quote Originally Posted by Elysia View Post
    A hint for you:
    Noone reads topics like these before posting. And those who do are smart enough to indent properly anyway.
    That's mostly how it is.
    i read topics like these and i am not smart enough to indent properly

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,709
    i read topics like these and i am not smart enough to indent properly
    That could mean that you have not yet understood the concept of scope, or you have problems configuring your text editor.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,583
    Quote Originally Posted by PunchOut View Post
    i read topics like these and i am not smart enough to indent properly
    Well, those who are smart enough figures it out by reading the topics, so in the end, they become smart and do not need to read "these" topics
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by 39ster View Post
    People mix spaces and tabs. Doesn't look nice.
    I wish this site would use indent tabs 4 spaces so my formatting doesn't get completely messed up when I post my nicely indented code...

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,583
    Ya, but that's typically a browser issue, isn't it?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    Ya, but that's typically a browser issue, isn't it?
    And how do you change the size of tabs in the browser? I don't know of any way. So keep it consistent, either spaces or tabs in a particular file.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  2. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 04:39 PM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 4
    Last Post: 01-15-2002, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21