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

  • Home
  • SEARCH
  • 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 7432747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:30:27+00:00 2026-05-29T09:30:27+00:00

in my application, i’m trying to achieve something like this: i have: data 0,

  • 0

in my application, i’m trying to achieve something like this:

i have:

  • data 0, data 1, data 2, … data n.
  • some parameters to pass

flow:

  1. starts the program with some parameters and write data 0 into stdin
  2. the program does calculation according to the passed data “data 0” and parameters
  3. “wait” for new stdin and (clear old stdin,buffer and variables?)
  4. repeat 1 ~2 when i put data 1, data 2… and so on
  5. when reaches data n, terminate(or if i input a abort code to stdin telling the program to terminate).

maybe something like this?(pseudo code):

int main(int argc, char *argv[])
{
get parameters();
int fslen = data size
char *c = (char *)malloc(fslen);
fgets(c, fslen, stdin);

while((c != null) || (c != Terminate code?))
{       
    do calculations with int c;
    clear c;
}
return 0;
}

or is their a better approach?

or is it just bad practice to do things this way?
if so, please explain

  • 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-29T09:30:28+00:00Added an answer on May 29, 2026 at 9:30 am

    There’s really not any better way, at least as far as I’m aware, to read and parse line input than to read and parse line input.

    By default, stdin should be blocking, so your ‘waiting’ criterion should be taken care of automagically.

    You will, however, need two loops if you’re going to be reading lines and then parsing the lines for codes:

    int main(int argc, char *argv[])
    {
        /* initial parameter/buffer setup goes here */
    
        while (fgets(buffer, bufferlen, stdin)) {
            for (c = buffer; *c != '\0' && *c != terminatingcode; c++) {
                /* calculations go here! ... they sure do! </homer> */
            }
            if (*c == terminatingcode || ferror(stdin))
               break;
        }
    }
    

    Be aware that fgets() can “fail” here for perfectly innocent reasons, and you need to become familiar with feof() and ferror() to make sure you’re using the interface correctly; I’m unsure whether my use in the code above is consistent with what you want/need the code to do.

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

Sidebar

Related Questions

Application stores configuration data in custom section of configuration file. This information is used
Application requests KML data through AJAX from server. This data is stored in javascript
Application has 7-8 activities, so I have create an application with some background music
My application scenario is like this: I want to evaluate the performance gain one
Application has an auxiliary thread. This thread is not meant to run all the
Application : HTA (therefore IE) This is an application that uses SendKeys to populate
Application-Stack: Rails3, CanCan, Devise, Shoulda I've got some nested Resources and want to test
Application I am developing does some kind of server-side authorization. Communication is done via
The application I'm currently writing is using MVVM with the ViewModel-first pattern. I have
Application: This is a workshop proposal system for a conference. A user can create

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.