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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:01:19+00:00 2026-06-10T00:01:19+00:00

I write a program for encrypting. #include <stdio.h> #include <string.h> #include <stdlib.h> #include <readline/readline.h>

  • 0

I write a program for encrypting.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <readline/readline.h>

int main(void) {
    char * plain;
    char letter;
    int value;
    int index;

    plain = readline("Please input your plain text: ");
    printf("Please input your key (included negatives): ");
    scanf("%i", &value);

    for (index = 0; index < strlen(plain); index++) {
        letter = plain[index];

        if (letter >= 'A' && letter <= 'Z') {
            fprintf(stderr, "%c", (letter - 'A' + value) % 26 + 'A');
        }

        else if (letter >= 'a' && letter <= 'z') {
            fprintf(stderr, "%c", (letter - 'a' + value) % 26 + 'a');
        }
        else {
            fprintf(stderr, "%c", letter);
        }
    }
    fprintf(stderr, "\n");
    free(plain);
}

And I did some benchmarks:

biergaizi@localhost ~/learning_c/test $ time ./caesar_readline < lots_of_letters 2> c_readline_result > /dev/null

real    2m31.212s
user    2m30.776s
sys     0m0.165s

The program spend too much time to read the text from standard input. If I remove > /dev/null, I can see the program is reading from standard input, too slow!

I also wrote version without GNU Readline, it is very fast.

Why? And How can I solve it?

  • 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-10T00:01:20+00:00Added an answer on June 10, 2026 at 12:01 am

    Because the feature it provides.

    provides a set of functions for use by applications that allow users
    to edit command lines as they are typed in. Both Emacs and vi editing
    modes are available.

    I think you can just use open function

    if (!strcmp(*argv, "-"))
      fd = fileno(stdin);
    else fd = open(*argv, O_RDONLY|O_NONBLOCK, 0);
    

    and provide – as filename if you want read from stdin

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

Sidebar

Related Questions

I want to write a program which replaces each specific letter by text according
I have to write program that counts how many different letters are in string.
I'm willing to write program that after 5 sec shows text that was hidden
If I write program in python 2.7 and I want to run another script
Write a program to determine whether a computer is big-endian or little-endian. bool endianness()
I write a program to delete a file from somewhere of my harddisk in
I write a program to verify this website: www.alipay.com which root CA cert should
I want to write a program in Prolog that confirms if a b-tree of
I want to write a program to contact a PHP script online, and show
I need to write a program that prints 0.(03) for input 1 and 33.

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.