Thread: why the compiler skips this line..

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    why the compiler skips this line..

    it just skips over this
    Code:
    scanf("%c",&var);
    instead of letting me input a char in var
    ??

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Look in some of the half-dozen other of your threads which deal specifically with scanf issues.

    And no, it's YOUR code which is the issue, not your compiler.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    there is no mistake
    if it was written in a wrong way
    the program wouldnt have ran from the beggining

    why its skipping this line
    ??

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by transgalactic2
    there is no mistake
    if it was written in a wrong way
    the program wouldnt have ran from the beggining
    You code can be wrong without causing a compile error.

    Quote Originally Posted by transgalactic2
    why its skipping this line
    ??
    Because you wrote the code such that the flow of control skips that statement with the given input to your program, or maybe the flow of control does not skip that statement, but you have deceived yourself into believing that it does.
    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

  5. #5
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    so the scanf is correct?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by transgalactic2
    so the scanf is correct?
    Maybe. Without knowing the problem, the context and what exactly is var, concluding the correctness (or lack thereof) of that call of scanf is foolish.

    For example, is this correct?
    Code:
    foo();
    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

  7. #7
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    maybe its skipping because of the \0 in the buffer

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Okay, enough of games. Post the smallest and simplest compilable program that demonstrates the problem.
    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

  9. #9
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by transgalactic2 View Post
    maybe its skipping because of the \0 in the buffer
    It probably lies in the code that goes before scanf() so it's best to post the code snippet.

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > there is no mistake
    ROFLMAO - so says you with 1500 posts and no idea STILL how to use scanf properly.

    Originally posted by brewbuck
    Sit back and break out the marsh mallows.

    You continue to use broken ideas, then post 1-liners with NO context, then complain that it doesn't work, and then complain at people trying to help you (futile: adj - helping transgalactic2)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiler Error Help
    By DarkDot in forum C++ Programming
    Replies: 2
    Last Post: 04-03-2007, 11:40 PM
  2. print line by line from a file
    By SoFarAway in forum C Programming
    Replies: 3
    Last Post: 02-18-2005, 01:36 PM
  3. Read only one line using seekg
    By RedZippo in forum C++ Programming
    Replies: 3
    Last Post: 03-31-2004, 11:10 PM
  4. if is faster than switch?
    By skorman00 in forum C++ Programming
    Replies: 32
    Last Post: 03-06-2004, 01:15 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM