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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:18:35+00:00 2026-06-02T02:18:35+00:00

There’s no way to know how many arguments there are; the user can provide

  • 0

There’s no way to know how many arguments there are; the user can provide a list of indeterminate length.

I’m very bad with C. How can I read arguments out of the command-line array and into a new array of strings?

Frankly I don’t even know how to make an array of separate strings, if I’m going to be honest. An example would be super-helpful.

  • 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-02T02:18:37+00:00Added an answer on June 2, 2026 at 2:18 am

    Yes there is.

    If you look at the main function’s full prototype:

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

    argc: This is the argument counter, it contains the number of argument given by the user (Assumin the command is cd, entering cd home will give argc = 2 because the command name is always argument 0)

    argv: This is the arguments values, it is an array of size argc of char* pointing to the arguments themselves.

    env: This is a table (as argv) containing the environment when the program is called (through a shell for example, it’s given with env command).

    As for an example of making an array of things: Two ways are possible:

    First, a fixed-length array:

    char tab[4]; // declares a variable "tab" which is an array of 4 chars
    tab[0] = 'a'; // Sets the first char of tab to be the letter 'a'
    

    Second, a variable-length array:

    //You cannot do:
    //int x = 4;
    //char tab[x];
    //Because the compiler cannot create arrays with variable sizes this way
    //(If you want more info on this, look for heap and stack memory allocations
    //You have to do:
    int x = 4; //4 for example
    char *tab;
    tab = malloc(sizeof(*tab) * x); //or malloc(sizeof(char) * x); but I prefer *tab for
    //many reasons, mainly because if you ever change the declaration from "char *tab"
    //to "anything *tab", you won't have to peer through your code to change every malloc,
    //secondly because you always write something = malloc(sizeof(*something) ...); so you
    //have a good habit.
    

    Using the array:

    Any way you choose to declare it (fixed-size or variable-size), you always use an array the same way:

    //Either you refer a specific piece:
    tab[x] = y; //with x a number (or a variable containing a value inside your array boundaries; and y a value that can fit inside the type of tab[x] (or a variable of that type)
    //Example:
    int x = 42;
    int tab[4]; // An array of 4 ints
    tab[0] = 21; //direct value
    tab[1] = x; //from a variable
    tab[2] = tab[0]; //read from the array
    tab[3] = tab[1] * tab[2]; //calculus...
    //OR you can use the fact that array decays to pointers (and if you use a variable-size array, it's already a pointer anyway)
    int y = 21;
    int *varTab;
    varTab = malloc(sizeof(*varTab) * 3); // An array of 3 ints
    *varTab = y; //*varTab is equivalent to varTab[0]
    varTab[1] = x; //Same as with int tab[4];
    *(varTab + 2) = 3; //Equivalent to varTab[2];
    //In fact the compiler interprets xxx[yyy] as *(xxx + yyy).
    

    Star-ing a variable is called dereferencing. If you don’t know how this works I highly suggest you take a look.

    I hope this is explained well-enough. If you still have questions please comment and I’ll edit this answer.

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

Sidebar

Related Questions

There are many string matching algorithms can be used to find a pattern (string)
There is any way to set the generic type (T) of class in the
There is a table view with three sections. The last section may contain many
There is some contradiction in the api documentation: on one location: https://developer.foursquare.com/docs/responses/user on another
There is a list standard python exceptions that we should watch out, but I
there can be two productions from which we can do the reduction. After giving
There are often times when you know for a fact that your loop will
I know there's a lot of other questions out there that deal with this
There are many tutorials that talk about deleting index.php from the url. But I
There seem to be many ways to define singletons in Python. Is there a

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.