Like Tree3Likes

scanf trouble: easy code, inexperienced programer

This is a discussion on scanf trouble: easy code, inexperienced programer within the C Programming forums, part of the General Programming Boards category; How do I get it to stop printing Code: x is greater than y when I don't input anything?...

  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,211
    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%.

  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,211
    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%.

  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
    289
    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
    Crossfire likes this.

Page 2 of 2 FirstFirst 12
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, 05: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, 04:28 AM
  4. scanf trouble
    By sloke in forum C++ Programming
    Replies: 4
    Last Post: 11-16-2005, 02:31 PM
  5. Having trouble with scanf function
    By cw3od in forum C Programming
    Replies: 2
    Last Post: 11-28-2001, 02:58 PM

Tags for this Thread


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