Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3992172
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:43:59+00:00 2026-05-20T06:43:59+00:00

Sorry for the long title. I am developing a network program in C which

  • 0

Sorry for the long title. I am developing a network program in C which may display messages received from network on stdout and accept user input on stdin via the GNU readline library.
The problem is, when the user is typing commands on the main thread via readline, a network message arrives and output to stdout, which will produce something like this:

Scenario:

Input: 1234567890
Network message: Hello
The network message arrives when the user just typed “7”

Actual output on terminal:

Input> 1234567Hello
890_

Is there a way to have the output like this?

Hello
Input> 1234567890_

p.s. _ is the cursor.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T06:44:00+00:00Added an answer on May 20, 2026 at 6:44 am

    OK I have found a solution to this after searching around and made the following replacement to printf(). By using rl_replace_line(“”, 0) it will clear the current line and place the cursor at the start of line, then I can print a line of message, and then restore the readline prompt, replace the original line back in place, and restore the cursor position.
    However, this hack requires any call to this printf function to include a \n at the end, otherwise the line will be overwritten by readline.

    #define printf(...) my_rl_printf(__VA_ARGS__)
    void my_rl_printf(char *fmt, ...)
    {
        int need_hack = (rl_readline_state & RL_STATE_READCMD) > 0;
        char *saved_line;
        int saved_point;
        if (need_hack)
        {
            saved_point = rl_point;
            saved_line = rl_copy_text(0, rl_end);
            rl_save_prompt();
            rl_replace_line("", 0);
            rl_redisplay();
        }
    
        va_list args;
        va_start(args, fmt);
        vprintf(fmt, args);
        va_end(args);
    
        if (need_hack)
        {
            rl_restore_prompt();
            rl_replace_line(saved_line, 0);
            rl_point = saved_point;
            rl_redisplay();
            free(saved_line);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for the long question title. I guess I'm on to a loser on
Sorry for a long question and not a very descriptive title, but my problem
Sorry for long winded title, this makes a lot more sense with an example.
Sorry for the long title, but I couldn't think of another way to put
Sorry for the long title, but it seems most descriptive for my question. Basically,
Sorry for the long and yet still somehow vague title! A friend of mine
My question (which will follow after this, sorry about the long intro, the question
Sorry for the long winded title, but the requirement/problem is rather specific. With reference
Sorry for long title but my concern is with constructing an ajax based application.
Sorry for long title, I don't know even the way on how to express

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.