Thread: printf() Question

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    132

    printf() Question

    Hello, everyone. How do I use the printf() function to print the following (only the part between double quotes) and then wait for input over the __ part, but without deleting it before the actual input?

    "Please enter an integer: __"

    Thanks in advance!

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    I would say that this is not possible in standard C...
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    200
    You could try something like this (but add error checking to scanf()):

    Code:
    #include <stdio.h>
    
    int main(void)
    {
        printf("Go: __\b\b");
        fflush(stdout);
    
        int i;
        scanf("%d", &i);
        printf("Got: %d\n", i);
    }
    On the other hand, I wouldn't bother - it's more "normal" for people to see a prompt with no underscores when typing at a terminal, and going along the path of least surprise for your users is always a good thing.
    Programming and other random guff: cat /dev/thoughts > blogspot.com (previously prognix.blogspot.com)

    ~~~

    "The largest-scale pattern in the history of Unix is this: when and where Unix has adhered most closely to open-source practices, it has prospered. Attempts to proprietarize it have invariably resulted in stagnation and decline."

    Eric Raymond, The Art of Unix Programming

  4. #4
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Apparently I was wrong
    Thanks John
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. printf question
    By ranjit89 in forum C Programming
    Replies: 8
    Last Post: 11-01-2011, 05:37 AM
  2. a question on 'printf'
    By xinwu in forum C Programming
    Replies: 2
    Last Post: 12-12-2010, 09:15 AM
  3. scanf and printf question
    By mmattson07 in forum C Programming
    Replies: 8
    Last Post: 10-11-2009, 01:31 PM
  4. printf() question
    By John Connor in forum C Programming
    Replies: 3
    Last Post: 02-08-2008, 03:52 PM
  5. printf question
    By Geko in forum C Programming
    Replies: 1
    Last Post: 01-14-2008, 01:24 PM