Thread: New line in C

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    7

    New line in C

    Say one line on my code is 100 characters long. The requirement is 70 charaters per line just for the sake of layout. Basically, how do I make one line of code into two lines?

    Would I just press enter? Or would the compile recognise the enter and do something else different to it?

    Help appreciated.

  2. #2
    wise_ron wise_ron's Avatar
    Join Date
    May 2006
    Posts
    75

    can you post your program. I hope this helps

    Code:
    Would I just press enter?
    Iam not sure what you are talking about but i think you wan to creat a newline.

    Example if my code is:

    ajlkjfdlkajlfdkjaklajlfkjda = 100 characters
    adkjfhakf = 70 characters

    you need to use the command \n whever you want to end the code

    example:

    Code:
    #include<stdio.h>
    main()
    {
      printf("adkjfhakf \n");
      printf("ajlkjfdlkajlfdkjaklajlfkjda");
      return 0;
    }
    Wise_ron
    One man's constant is another man's variable

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Whitespace can be used pretty much as you please. You can have long lines, or short, either is fine; though I prefer ~78 characters per line maximum if possible.
    Talking about non-strings here, you can break lines pretty much when ever you like, so long as you're not chopping a function name in half, or a variable name, or something like that.
    Code:
    int x;
    int
    y;
    int
    z
    ;
    All of that is fine, this isn't:
    Code:
    in
    t x;
    Your compiler will no longer see "in" and "t" as "int". So other than stuff like that, you are free to scatter whitespace as needed.

    If that's not what you're talking about, please clarify.

    For strings, it will concatenate consecutive strings to be a single. Like so:
    Code:
    char *foo = "Hello"
    " "
    "World!";
    Those three will be combine into a single "Hello World!".


    Quzah.
    Last edited by quzah; 09-29-2006 at 02:08 AM.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    7
    Thanks for both of the reply. But yeah, I didn't mean printf, I just meant normal instructions.

    And I tried just using enter and the program worked normal. So yeah, it's all good.

    Edit* I was referring to quzah's first section. Pardon the inclarity.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by dwlu244
    Thanks for both of the reply. But yeah, I didn't mean printf, I just meant normal instructions.

    And I tried just using enter and the program worked normal. So yeah, it's all good.

    Edit* I was referring to quzah's first section. Pardon the inclarity.
    When writing macros however, you must end your line with a \ if you wish to continue the macro to the next line.
    Code:
    #define FOO(BAR)      \
        ( (BAR) == EMPTY  \
            ? "Restock!"  \
            : "Drink up!" \
        )
    Naturally they don't have to all be lined up...

    Quzah.
    Last edited by quzah; 09-29-2006 at 02:23 AM.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to do encryption in C
    By sankarv in forum C Programming
    Replies: 33
    Last Post: 12-28-2010, 11:01 AM
  2. Reading a file line by line
    By Raskalnikov in forum C Programming
    Replies: 8
    Last Post: 03-18-2009, 11:44 PM
  3. Pointer and Polymorphism help.
    By Skyy in forum C++ Programming
    Replies: 29
    Last Post: 12-18-2008, 09:17 PM
  4. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 04:13 PM
  5. Finding carriage returns (\c) in a line
    By JizJizJiz in forum C++ Programming
    Replies: 37
    Last Post: 07-19-2006, 05:44 PM