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 8755255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:49:01+00:00 2026-06-13T13:49:01+00:00

I have a chat client that takes in input in raw terminal mode, but

  • 0

I have a chat client that takes in input in raw terminal mode, but I don’t know about handling input in this mode. I need to know 2 things:

  • How can I read the input in character-by-character and display it? Do I have to have some sort of a read loop that reads one character at a time and stores it in a buffer?
  • If I want my server to process the input on new line entry, do I have to scan each character as it comes into my buffer and look for \n?

Also, an example character-by-character read loop that flushes on \n would be really great to see. Thanks!

  • 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-06-13T13:49:02+00:00Added an answer on June 13, 2026 at 1:49 pm

    I recommend the GNU readline library for this. It takes care of the tedious work of getting lines of input, and allows the user to edit his line with backspace, left and right arrows, etc, and to recall older command using the up arrow and even search for older command using ^R, etc. Readline comes installed with typical unix-like distributions like linux, but if you don’t have it, you can find it here

    Edit: Here is a minimal readline example:

    #include <stdio.h>
    #include <readline/readline.h>
    #include <readline/history.h>
    
    int main(int argc, char ** argv)
    {
        while(1)
        {
            char * line = readline("> ");
            if(!line) break;
            if(*line) add_history(line);
            /* Do something with the line here */
        }
    }
    

    Compile with gcc -o test test.c -lreadline -lncurses.

    If you can’t use readline, getline is an alternative:

    #include <stdio.h>
    int main()
    {
        char * line = NULL;
        size_t len;
        while(getline(&line, &len, stdin) >= 0)
           printf("I got: %s", line);
    }
    

    If even getline is unacceptable, you can use fgets. It will not dynamically allocate a buffer of suitable size, so too long lines will be truncated. But at least it is standard C:

    #include <stdio.h>
    int main()
    {
        char buf[1000];
        while(fgets(buf, sizeof(buf), stdin)
            printf("I got: %s, line);      
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a Flash based chat client that displays messages posted by users
So I am using node.js and socket.io. I have this little program that takes
I currently have a chat client that communicates successfully with a server . I
I have a chat client that continuously polls a server and fetches new messages.
I have a simple chat client set up that allows users to login with
i have a java chat server & client, that works fine. I made a
I am working on a C# chat client that needs to have a sending
I have heard that web-based chat clients tend to use networking frameworks such as
so... I have a simple chat client like so: class ChatClient(sleekxmpp.ClientXMPP): def __init__(self, jid,
I'm writing chat client/server app with c# and I have problem with threading. I

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.