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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:07:35+00:00 2026-05-25T02:07:35+00:00

i have to implement a few CLI features and now I am trying to

  • 0

i have to implement a few CLI features and now I am trying to use readline() so that the user can edit or go through their commands. Its working so far in that it allows the user to enter their commands and scroll through the history. Its when the user tries to edit the command. The cursor somehow manages to pass the command and go into the prompt eg
“desktop r1234|5$: ls” where “desktop r12345(sp)$: ” is the prompt showing working directory & root dir; and “|” is the cursor. The cursor should stop in-between ‘$’ and ‘ls’ ie “desktop r12345$:| ls” .The showWrkngDir() method just displays a prompt just like a normal terminal.

int main (int argc, char * argv[])
{

    showWrkngDir();
    static char *line_read = (char *)NULL;
    using_history();
    rl_readline_name = basename(argv[0]);
    if (line_read)
    {
            free (line_read);
            line_read = (char *)NULL;
    }

    while(strcmp((line_read = readline ("")) , "EXIT") != 0)
    {
            if (line_read && *line_read)
                    add_history (line_read);

            tokenize(line_read);
            showWrkngDir();
    }

    return 0;
}


void showWrkngDir()
{
    char curDir[MAX_COMMAND_SZ];
    char *env;

    getcwd(curDir, sizeof(curDir));
    env = (char *)getenv("USER");

    printf("%s ",basename(curDir));

    printf("%s(sp)$ ", env);
}
  • 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-25T02:07:36+00:00Added an answer on May 25, 2026 at 2:07 am

    I’m fairly sure that readline wants to display the prompt itself, because sometimes it needs to erase the entire screen line and redraw it from scratch. This happens especially when browsing through history, but also when editing a command that spills over to the next line, or when ^L is pressed.

    Give your prompt as the argument to readline(),

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data access library that has a few classes that all implement
I have an ASP.NET site that uses themes to implement a few variations. I
I have a method that has a few pointers as parameters. This method can
i have to implement Picasa client for iPhone. I have few queries in that
I have a simple C++ DLL that implements a few custom actions for a
I have found that I often have to implement some sort of a scheduler
I have a Silverlight (v3) application that users can drag controls (e.g. Shapes, Images)
For the past few days, I have been trying to figure out how to
I have a few classes such that: public class XMLStatusMessage extends XMLMessage {} public
I have an abstract functor class that overloads operator() and derived objects that implement

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.