Thread: I have 2 Q's for you all

  1. #1
    -
    Join Date
    Feb 2003
    Posts
    47

    I have 2 Q's for you all

    Okey Question 1:
    What is the deal with
    Code:
     printf("wang\n");
     printf("wang\n");
    and...
    Code:
     printf("wang\n"
            "wang\n");
    if you have more text to display which is best to use?
    just a small one.

    Question 2:
    If you would like to have a look at my code in general, its not too big, see if you find anything im doing wrong, as it starts to get bigger i dont want messy code etc, any thoughts let them rip. keep in mind its no where nere done.
    code

  2. #2
    Registered User Twiggy's Avatar
    Join Date
    Oct 2001
    Posts
    43
    code:
    printf("wang\n");
    printf("wang\n");



    and...

    code:
    printf("wang\n"
    "wang\n");


    I think you mean.

    [code]
    printf("wang\nwang\n");

    printf("wang\n" "wang\n"); won't work I wouldn't think.
    [\code]

    That's just to simplify code and reduce space really. Two printf statements for two seperate lines can be avoided by the \n which means a newline.

  3. #3
    -
    Join Date
    Feb 2003
    Posts
    47
    >printf("wang\n" "wang\n"); won't work I wouldn't think.

    as far as i knew

    printf("wang\n" "wang\n");

    and

    printf("wang\n"
    "wang\n");

    were the same... white space is nothing. I know what \n is.
    I was talking more along the lines of the size of the .exe made, does it make a difference? speed wise etc. Look at my code for a better example of what i mean.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    (1) It usually doesn't matter. Most thinks most make are hardly mission critical, so it really doesn't matter here. However, you've got two schools of thought:

    (1a) Write readable code first and foremost. If it's clearer to use two statements, do so. If it looks better with a single call, go that route.

    (1b) Write efficient code next. Ideally, your code won't be horribly inefficient from its initial design, so you won't really need to focus on optimizing it with questions such as the above. However, if you want to know, it's less overhead to do a single function call than it is to have two. So the second of the two would be better.

    When in doubt, focus on readability.

    (2) There are a few points I'll note at a glance:

    (2a) Why the global variable?
    int Answer = 0;

    (2b) Never call 'main':
    Code:
    /* About the program */
    int About( void )
    {
        printf ( "\nRobinson's Quizzes -- 1.0\n\n"
                 "Robinson's Quizzes was created by Daniel Robinson\n"
                 "This program was made for my Year 12 Major Project.\n"
                 "Please send any requests or bugs to {email addy}\n\n" );
    
        system ("PAUSE");
        main();
        return 1;
    }
    You are not able to do this with a C99 compiler. It is no longer valid. It's not a good idea anyway, because of the stack overhead you'll run into with recursion.

    You call main in a bunch of functions. You should just be returning to the main function and continuing in your loop.

    [edit]Removed your email addy from the code snippet to save you from getting spammed to death.[/edit]

    Quzah.
    Last edited by quzah; 06-24-2003 at 04:03 AM.
    Hope is the first step on the road to disappointment.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Twiggy
    I think you mean.

    Code:
    printf("wang\nwang\n");
    
    printf("wang\n" "wang\n"); won't work I wouldn't think.
    I fixed your code tag. But no, both pieces of code are identical. The two strings will be concatenated as one. Since they are not seperated by a ',' in this instance, they are considered as a single argument. As such, like all strings like this, they're merged into a single string. The end result is both of those two printf statements are the same.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    -
    Join Date
    Feb 2003
    Posts
    47
    thanks for your help quzah, an extra function fixed the problem of calling main(). I use Borland C++ Builder 6, i thought it would have used a C99 compiler... Oh well.

    Thanks again.
    Cheers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Q's
    By pktcperlc++java in forum C++ Programming
    Replies: 15
    Last Post: 12-24-2004, 11:36 AM
  2. Couple of Q's.....
    By oobootsy1 in forum C++ Programming
    Replies: 18
    Last Post: 02-23-2004, 02:03 PM
  3. Qs about RAID0 & expandability
    By Markallen85 in forum Tech Board
    Replies: 2
    Last Post: 01-18-2004, 02:52 PM
  4. 2 q's: SPI_SETFLATMENU & platform SDK
    By Mithoric in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2003, 10:44 AM
  5. C and UNIX Q's?
    By Unregistered in forum C Programming
    Replies: 0
    Last Post: 06-13-2002, 05:39 AM