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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:50:21+00:00 2026-05-27T00:50:21+00:00

I have an existing program where a message (for example, an email, or some

  • 0

I have an existing program where a message (for example, an email, or some other kind of message) will be coming into a program on stdin.
I know stdin is a FILE* but I’m somewhat confused as to what other special characteristics it has. I’m currently trying to add a check to the program, and handle the message differently if it contains a particular line (say, the word “hello”). The problem is, I need to search through the file for that word, but I still need stdin to point to its original location later in the program. An outline of the structure is below:

Currently:

//actual message body is coming in on stdin
read_message(char type)
{

//checks and setup

if(type == 'm')
  {
    //when it reaches this point, nothing has touched stdin
        open_and_read(); //it will read from stdin
  }

//else, never open the message
}

I want to add another check, but where I have to search the message body.
Like so:

//actual message body is coming in on stdin
read_message(char type)
{

//checks and setup

//new check
if(message_contains_hello())   //some function that reads through the message looking for the word hello
{
     other_functionality();
}

if(type == 'm')
  {
        //when it reaches this point, my new check may have modified stdin
    open_and_read(); //it will read from stdin
  }

//else, never open the message
}

The problem with this is that to search the message body, I have to touch the file pointer stdin. But, if I still need to open and read the message in the second if statement (if type = ‘m’), stdin needs to point to the same place it was pointing at the start of the program. I tried creating a copy of the pointer but was only successful in creating a copy that would also modify stdin if modified itself.

I don’t have a choice about how to pass the message – it has to stay on stdin. How can I access the actual body of a message coming in on stdin without modifying stdin itself?
Basically, how can I read from it, and then have another function be able to read from the beginning of the message as well?

  • 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-27T00:50:22+00:00Added an answer on May 27, 2026 at 12:50 am

    The short answer is that you can’t. Once you read data from standard input, it’s gone.

    As such, your only real choice is to save what you read, and do the later processing on that rather than reading directly from standard input. If your later processing demands reading from a file, one possibility would be to structure this as two separate programs, with one acting as a filter for the other.

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

Sidebar

Related Questions

In my existing program, after completing some result I store it in a file.
I have an existing program we've developed as a large set of Eclipse plugins.
I have an existing MF COBOL 4.0 program with years of data in a
I have existing Linux shared object file (shared library) which has been stripped. I
I have an existing program that has its own main loop, and does computations
I have written a multithreaded program which does some thinking and prints out some
Background: I have some existing apps in the App Store and I have just
I have a J2SE program that I'm moving over to use JPA. The existing
I have to extend an existing program (Java-based, but this shouldn't count). This program
I have an existing winform app which didn't use Program.cs. I wanted to add

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.