Thread: for loop problem

  1. #1
    Registered User
    Join Date
    Jul 2014
    Posts
    4

    for loop problem

    Hello guys, a little newbie here. Can't figure out why it flows two times. Thanks!
    Attached Images Attached Images for loop problem-problem-jpg 

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    When you press a letter, then 'enter', two characters are being sent to the program - the letter you entered and the newline character. The first time through, "scanf()" reads the letter you entered. The next time through, it picks up the newline from the input buffer.

    More information, and some solutions, can be found here -> FAQ > How do I avoid a "dangling" newline when reading single character user input? - Cprogramming.com

  3. #3
    Registered User
    Join Date
    Jul 2014
    Posts
    4
    Well...worked. Many thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with While loop
    By Arthurdent in forum C Programming
    Replies: 5
    Last Post: 07-10-2011, 04:56 AM
  2. do while loop got problem
    By yangss in forum C Programming
    Replies: 4
    Last Post: 09-03-2010, 03:33 AM
  3. Problem with for loop
    By irsmart in forum C++ Programming
    Replies: 3
    Last Post: 09-29-2006, 04:26 PM
  4. Loop Problem
    By shawry in forum C Programming
    Replies: 5
    Last Post: 04-01-2006, 09:55 AM
  5. for loop problem
    By Makoy in forum C++ Programming
    Replies: 1
    Last Post: 12-25-2004, 10:08 AM