1. Not finding help here? Sign up for a free 30min 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!

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);
    printf("%\n");

    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

    jedishrfu

    Staff: Mentor

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

    http://courseweb.stthomas.edu/tpsturm/private/notes/qm300/ANSI.html

    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 Discussions: C programming question
  1. C programming question (Replies: 7)

  2. C programming question (Replies: 22)

  3. C programming question (Replies: 1)

  4. C programming question (Replies: 2)

  5. C programming question (Replies: 4)

Loading...