1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: C programming question

  1. Mar 22, 2013 #1
    How do you print text after a scanf statement on the same line? This is what i need the output to look like:

    Enter a number here: _%

    The _ is the scanf waiting for input. Now when i write the code like this:

    printf("Enter a number here: ");
    scanf("%d", &x);

    It wont put the % sign until after i input a value. How should i rewrite this to achieve what I need? thanks in advance!
  2. jcsd
  3. Mar 22, 2013 #2


    Staff: Mentor

    You can only do that if you use ansi screen codes to reposition the cursor after you've written the prompt line:


    These work only if your terminal window supports them and if its been enabled. I've used them in my awk scripts a lot.
  4. Mar 22, 2013 #3
    Alright. Thanks man
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted