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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:44:40+00:00 2026-05-25T06:44:40+00:00

Is it possible to save readline history in a text file and get the

  • 0

Is it possible to save readline history in a text file and get the history after I reopen my program…

char *line, *expansion;
int result;

stifle_history(7);

while ((line = readline(" $ ")) != NULL) {  

        result = history_expand(line, &expansion);

        rl_bind_key('\t',rl_complete);

        if (result)
                fprintf(stderr, "%s\n", expansion);

        if (result < 0 || result == 2) {
                free(expansion);
                continue;
        }

        strncpy(line, expansion, sizeof (line) - 1);
        free(expansion);
        read_history("history_file");
        write_history("history_file");

        register HIST_ENTRY **the_list;
        register int i;

        if (the_list)
                for (i = 0; the_list[i]; i++)
                        printf("%d: %s\n", i + history_base, the_list[i]->line);

        if (strlen(line) > 0) 
                add_history(line);

I improved my code a bit. Please show the the correct way how I can fix my code to save history in a text file retrieve it afterwards.

  • 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-25T06:44:41+00:00Added an answer on May 25, 2026 at 6:44 am

    According to the manual, you want to look at the write_history and read_history functions.

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

Sidebar

Related Questions

Is it possible to save a whole C# solution in one single text file?
How is it possible to save text from a text field when the user
How is it possible to save a file to the android phone rather than
is it possible to save the .xml file from the screen to main.xml? my
I had a quick question. Is it possible to save a file without actually
Is it possible to save some fields in the program, or do I have
Is it possible to save the layout diagram from a DBML file as a
Is it possible to save the result generated from a PHPUnit test as a
When working with htaccess files on Windows, is it possible to save the file
Is it possible to save . caf file into the photo library ? In

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.