Thread: scanf trouble: easy code, inexperienced programer

  1. #16
    Registered User
    Join Date
    Mar 2013
    Posts
    9
    How do I get it to stop printing
    Code:
    x is greater than y
    when I don't input anything?

  2. #17
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    Quote Originally Posted by ProBallChamp View Post
    So the above is not redundant; saying integer main and integer variable x and y?
    The code you've quoted defines main with a return type of int, and it also defines two objects of the type int with block scope and automatic storage duration. int was implied in earlier standards when the return type of a function was omitted, but that was changed in the later standards.

    also what does the main(void) mean/do?
    Since it's a function definition, it's synonymous "main()". It means that the function accepts zero parameters. "void" just makes that intention clearer.

  3. #18
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by ProBallChamp View Post
    Okay, I see what you are looking for, here are three working cases when I input a x and y respectively;
    From information you've given, none of the three cases you've supplied strike me as exhibiting a problem.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  4. #19
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    Quote Originally Posted by ProBallChamp View Post
    How do I get it to stop printing
    Code:
    x is greater than y
    when I don't input anything?
    It does that when you input a number greater than zero followed by end-of-file or rubbish, not when you don't input anything. You fix that by reading #11.

  5. #20
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by ProBallChamp View Post
    How do I get it to stop printing
    Code:
    x is greater than y
    when I don't input anything?
    You mean that the program prints "x is greater than y" before you have typed ANY input AT ALL to the program?

    That probably means a configuration problem affecting your build process (i.e. the executable you are running was produced by the compiler/linker from a superseded version of your source code). Delete all the object files and executable files, and rebuild your complete program from source. In an IDE, do "Build Clean" followed by "Build All".
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  6. #21
    Registered User
    Join Date
    Mar 2013
    Posts
    9
    Okay, if think I've got a substantial program now. Though, I still have much to learn. Thanks for all the help Grumpy and Barney

    Quote Originally Posted by grumpy View Post
    You mean that the program prints "x is greater than y" before you have typed ANY input AT ALL to the program?

    That probably means a configuration problem affecting your build process (i.e. the executable you are running was produced by the compiler/linker from a superseded version of your source code). Delete all the object files and executable files, and rebuild your complete program from source. In an IDE, do "Build Clean" followed by "Build All".

  7. #22
    Registered User
    Join Date
    Dec 2012
    Posts
    307
    so it works now?

    and although i dont look for attaboys, dont forget me! :P lol

  8. #23
    Registered User
    Join Date
    Mar 2013
    Posts
    9
    Thanks too Crossfire, thought you logged off, I now have a better understand of this concept than I did this morning.

    Quote Originally Posted by Crossfire View Post
    so it works now?

    and although i dont look for attaboys, dont forget me! :P lol

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Easy scanf() question
    By Roger in forum C Programming
    Replies: 3
    Last Post: 11-05-2009, 06:35 PM
  2. Replies: 23
    Last Post: 04-20-2009, 07:35 AM
  3. Seg fault in easy, easy code
    By lisa1901 in forum C++ Programming
    Replies: 11
    Last Post: 12-10-2007, 05:28 AM
  4. scanf trouble
    By sloke in forum C++ Programming
    Replies: 4
    Last Post: 11-16-2005, 03:31 PM
  5. Having trouble with scanf function
    By cw3od in forum C Programming
    Replies: 2
    Last Post: 11-28-2001, 03:58 PM

Tags for this Thread