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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T13:03:52+00:00 2026-06-18T13:03:52+00:00

I have the following program called Scorecommandline : int main (int argc, char *argv[])

  • 0

I have the following program called Scorecommandline:

int main (int argc, char *argv[]) {
    if (argc!=15) {
        usage();
        exit(1);
    }

    int iArray[14];
    int i = 0;
    while(1){
        if(scanf("%d",&iArray[i]) != 1){
        break;
        }
        i++;
        if(i == 14) {
        i = 0;
        }
    }

    int age = atoi(iArray[1]);
    int b_AF = atoi(iArray[2]);
    int b_ra = atoi(iArray[3]);
    int b_renal = atoi(iArray[4]);
    int b_treatedhyp = atoi(iArray[5]);
    int b_type2 = atoi(iArray[6]);
    double bmi = atof(iArray[7]);
    int ethrisk = atoi(iArray[8]);
    int fh_cvd = atoi(iArray[9]);
    double rati = atof(iArray[10]);
    double sbp = atof(iArray[11]);
    int smoke_cat = atoi(iArray[12]);
    int surv = atoi(iArray[13]);
    double town = atof(iArray[14]);

    double score = cvd_femal(age,b_AF,b_ra,b_renal,b_treatedhyp,b_type2,bmi,ethrisk,fh_cvd,rati,sbp,smoke_cat,surv,town,&error,errorBuf,sizeof(errorBuf));
    if (error) {
        printf("%s", errorBuf);
        exit(1);
    }
    printf("%f\n", score);
}

in which I have a .dat file intended to be used for the args in this program, however if I type:

cat testscandata.dat | ./ScorecommandLine

the program does not read the file in as the parameters for the program. How do I solve this?

Thanks

  • 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-18T13:03:54+00:00Added an answer on June 18, 2026 at 1:03 pm

    You are confusing two different ways of passing input into a program. You can pass arguments to main in a program by invoking the command from the command-line and listing the arguments. For example:

    ./ScoreCommandLine 1 2 3 4 5 6 7 8 9 10 11 12 13 14
    

    These arguments will be passed into main through argv.

    You can also pipe input into a program by sending in data through stdin by using pipes and redirection:

    SomeCommand | ./ScoreCommandLine
    

    This will take the output of SomeCommand and use that as the stdin stream in ScoreCommandLine. You can read it by using scanf, etc.

    In your case, you should either rewrite the program so that you aren’t expecting all the arguments to be passed in through the command-line, or you should use the xargs utility to convert stdin into command-line arguments:

    xargs ./ScoreCommandLine < testscandata.dat
    

    Hope this helps!

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

Sidebar

Related Questions

I have following simple program: import std.stdio; int main(string[] argv) { writeln(Hello, world!); return
I have a Java program called Main.java, it is located in the following directory:
Hi I have the following program. When I compile on the terminal gcc main.c
I have following code #include <iostream> #include<exception> #include <cstdlib> int main(){ for (int i
For the following program: int DivZero(int, int, int); int main() { try { cout
Let's imagine that I have following architecture: Dodo singleton class in libdodo Main program
In the following program abort method is called even when I have got the
I have the following code: #include <iostream> #include <string> #include sqlite3.h int main() {
I have the following function, that is called once in my program. When there
I have the following program void allocVars(){ m_window = new GLWindow(); //glGenTexture() is called

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.