Thread: doubles printf in a recursive function?

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    10

    doubles printf in a recursive function?

    Hi, in a project I use a recursive function and inside the function after a certain process I printf something but while running, the program writes it two times... I couldn't figure out the reason... Any help would be appreciated, thanks.

    This is the code:

    Code:
                    printf("%f saniyede bulundu...",elapsed);
                    printf("\n Continue to find higher value? y-n: ");
                    scanf("%c",&chr);

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You probably need to be aware that when you enter a response here you hit two keys: 'y' and 'enter-key', and therefore you get two inputs to this loop/recursion/whatever it is. If you want to ignore things like enter-key, you can do
    Code:
    scanf(" %c", &chr);

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    10
    I think that worked thanks a lot I will make some tests to make sure though =)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  4. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  5. error in program????
    By SpEkTrE in forum C Programming
    Replies: 5
    Last Post: 11-24-2003, 06:16 PM