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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:17:24+00:00 2026-06-11T12:17:24+00:00

Hello I’m new with C and I’m trying to start this lab where the

  • 0

Hello I’m new with C and I’m trying to start this lab where the command syntax is to first list any command line flags then list one or more file names.

I’m having trouble organizing how I want to scan the input arguments and differentiating them between flags and file names.

I thought of doing a loop to see if the argument is a flag or file name. But I’m unsure how to begin implementing it. Since the first 4 arguments can be potential flags in any order then anything after is the file name. But it is also possible for no flags to be given and just start with filenames. I don’t know at all how to initalize this loop to go through each argument 1 by 1. Can anyone help please?

Example of possible command line arguments:

wc fcopy.c head.c (no flags given just file names)
wc -l -c -w -L fcopy.c head.c a.exe (flags given and multiple files)
wc -l -w -c -L fcopy.c (flags given and 1 file name)
  • 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-11T12:17:26+00:00Added an answer on June 11, 2026 at 12:17 pm

    Reading command line args one by one is pretty simple:

    int main( int argc, // Number of strings in array argv char *argv[])
    

    The two basic args to a C function are argc (int number of args), and argv (an array of strings for the args)

    The first string is always the name of the program that is running, after that is the args that were passed over the command line.

    if(argc > 1)
        for( count = 1 count < argc; count++ )
            printf("%s", argv[count]);
    

    Will display to the screen each of the arguments passed in past the name of the calling program.
    I assume your flags are passed with a “-” as the first character? If so, you can check the contents of the first character in each string for a ‘-‘ to tell if its a flag or not.

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

Sidebar

Related Questions

hello friends i am trying to get a list of user id and want
Hello Guys I am trying to figure out why i am gettings this error
Hello i have this code var queue = new BlockingCollection<int>(); queue.Add(0); var producers =
Hello All I am trying to flatten a list in Ocaml. I am a
Hello There, I am new to phonegap.I am trying to record a audio clip
Hello I'm trying to add the select-all, cut, copy and paste command in my
Hello I have like this 2 tables class User public int UserId{get;set;} { ....
Hello i'm doing a application in php, and i have a list of items
Hello I've got this query to get users by email, which is an unique
Hello I wrote an application and while deploying shows error in line mCamera=Camera.open(); Where

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.