1. PF Contest - Win "Conquering the Physics GRE" book! Click Here to Enter
    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!

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
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted

Similar Threads - programming question Date
C: Question on file handling Nov 7, 2015
Programming assignment question (Java) Aug 15, 2014
Programming question Nov 26, 2013
MATLAB Programming Loops Question Oct 12, 2013
Linear Programming Exam Question Aug 8, 2013