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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:28:21+00:00 2026-06-11T11:28:21+00:00

Hello I have a project I’m doing and I need my program to run

  • 0

Hello I have a project I’m doing and I need my program to run from the command line and be able to read flags and file names that will be used in the program.

This is my current code. It compiles without entering any flags. I don’t think my GetArgs does anything. I had help with that part of the code.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 1024
#define IN 1 /* inside a word */ 
#define OUT 0 /* outside a word */
/* count lines, words, and characters in input */

int numInputArgs;
int idx;
void GetArgs (int argc, char **argv){

for (idx = 1; idx < 4;  idx++) {
    if (strcmp(argv[idx], "-c") == 0) {
        printf("Flag -c passed\n");
        break;
    }
    else if (strcmp(argv[idx], "-w") == 0) {
        printf("Flag -w passed\n");
        break;
    }
    else if (strcmp(argv[idx], "-l") == 0) {
        printf("Flag -l passed\n");
        break;
    }
    else if (strcmp(argv[idx], "-L") == 0) {
        printf("Flag -L passed\n");
        break;
    }
    else {
        printf("Error: unknown flag\n");
        exit(-1);
    }
}
 }// end GetArgs

void lineWordCount ( ) {

int c, nl, nw, nc, state;


    state = OUT; nl = nw = nc = 0; 
    while ((c = getchar()) != EOF) {
            ++nc;

        if (c == '\n')
            ++nl; 

        if (c == ' ' || c == '\n' || c == '\t')
            state = OUT; 

        else if (state == OUT) {
            state = IN; ++nw;
        } 
        printf("%d %d %d\n", nl, nw, nc);
    }
 }// end lineWordCount








 int main(int argc, char **argv){

GetArgs(argc, argv);
lineWordCount();
printf("Hello");

//fclose( src );
}
  • 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-11T11:28:23+00:00Added an answer on June 11, 2026 at 11:28 am

    You can either use a standard function like getopt() as mentioned by @Joachim, if it is available on your system, or you can code it yourself. If you have a complicated command line syntax, getopt() might be better suited – if you only need to check for a limited set of flags, it might be easier to code it yourself, for example:

    void GetArgs (int argc, char **argv){
       int idx = 0;
    
       for (idx = 1; idx < argc;  idx++) {
           if (strcmp(argv[idx], "-a") == 0) {
              printf("Flag -a passed\n");
           } else if (strcmp(argv[idx], "-b") == 0) {
              printf("Flag -b passed\n");
           } else if (strcmp(argv[idx], "-c") == 0) {
              printf("Flag -c passed\n");
           } else {
              printf("Error: unknown flag %s\n");
           }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I am in the process of doing a school project, where we have
So I have a main.py file inside /home/richard/projects/hello-python directory: import sys sys.path.append('/home/richard/projects/hello-python') from Encode
Hello I have a page in an ASP.NET (website) project that writes a file
hello all i have code from open source project that im integrating into my
Hello all I have a project where I need to perform single value bindings
Hello I have this code that worked to load a dll from a project
Hello guys i have dataform in silverlight 4 project item source is: ItemsSource={Binding Data,
hello all i am working on a project in which i have a webpage
Hello Ruby/Rails/Merb developers! Im currently working on a web project that will have a
Hello I have two project in a .NET 4.0 framework visual studio solution. First

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.