Thread: Indent command

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    EDIT:
    Oh wait, I think I understand now.

    You're not talking about programming in C to improve some sample solutions that you encountered. You're talking about whether calling this command:
    Code:
    indent -as -nut -ts4 -bli0 -i4 -blf -nbfda -npsl -c0 -cd0 -nip -nlp -nprs -npcs -ncs -nsaf -nsai -nsaw  -l100 try3.c
    to indent C code looks nice to other C programmers. My answer is that it looks fine. Don't sweat the small stuff like this kind of subjective code style as precise details usually matter much less than reasonable consistency, which of course you'll achieve by auto-formatting with an indent command.
    Last edited by laserlight; 09-17-2021 at 08:07 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #2
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    138
    Quote Originally Posted by laserlight View Post
    No, it isn't. The supplied code does not do any indenting at all.


    I'm really confused: isn't it obvious that these are examples of programs that change the alphabetic case of the input? They have nothing to do with indenting of code. You cannot ident anything merely by calling toupper or tolower on each input character and then printing the result.

    I mean, this is the question stated in the page you linked to:

    Nothing at all about indenting.
    I just indented the first and second code with the given command. Let's see code as it is on link provided:

    Code:
    #include <stdio.h>
    #include <ctype.h>
    #include <string.h>
    
    
    char *getbasename(char *);
    
    
    /* convert input to lower or upper case depending on argv[0]*/
    int main(int argc, char *argv[])
    {
        int c, (*convert)(int) = NULL;
        char* bn;
    
    
        if (strcmp((bn = getbasename(argv[0])), "lower") == 0)
            convert = tolower;
        else if (strcmp(bn, "upper") == 0)
            convert = toupper;
        else
            return 1;
        while ((c = getchar()) != EOF)
            putchar((*convert)(c));
        return 0;
    }
    
    
    char *getbasename(char *s)
    {
        char *p;
        char *base;
    
    
        for (base = p = s; *p != '\0'; p++)
            if (*p == '/')
                base = p;
        return base + 1;
    }
    Tabs before some statements are 8 spaces (on some sites anyway). With the first command they became 4:

    Code:
    #include <stdio.h>
    #include <ctype.h>
    #include <string.h>
    
    
    char *getbasename(char *);
    
    
    /* convert input to lower or upper case depending on argv[0]*/
    int main(int argc, char *argv[])
    {
        int c, (*convert) (int) = NULL;
        char *bn;
    
    
        if(strcmp((bn = getbasename(argv[0])), "lower") == 0)
            convert = tolower;
        else if(strcmp(bn, "upper") == 0)
            convert = toupper;
        else
            return 1;
        while((c = getchar()) != EOF)
            putchar((*convert) (c));
        return 0;
    }
    
    
    char *getbasename(char *s)
    {
        char *p;
        char *base;
    
    
        for(base = p = s; *p != '\0'; p++)
            if(*p == '/')
                base = p;
        return base + 1;
    }
    Last edited by ordak; 09-17-2021 at 08:12 AM. Reason: added some info

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to properly indent and format a source code?
    By nerio in forum C Programming
    Replies: 10
    Last Post: 02-05-2016, 11:17 AM
  2. How do you indent: spaces or tabs?
    By EVOEx in forum General Discussions
    Replies: 51
    Last Post: 09-24-2009, 07:10 AM
  3. How far do you indent?
    By dwks in forum A Brief History of Cprogramming.com
    Replies: 33
    Last Post: 09-17-2005, 04:36 PM
  4. how to indent a file.
    By hakim12 in forum C++ Programming
    Replies: 2
    Last Post: 01-30-2003, 02:55 PM
  5. Indent code
    By boontune in forum C++ Programming
    Replies: 3
    Last Post: 01-23-2003, 11:27 AM

Tags for this Thread