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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:34:17+00:00 2026-05-29T22:34:17+00:00

I don’t like re-inventing the wheel. Is there a standard or Linux specific function

  • 0

I don’t like re-inventing the wheel.

Is there a standard or Linux specific function to transform a C style string (char*)
to a char** style array of strings format like that passed into main?

i.e. given:

const char* s = "-n file -m -o output"

Dynamically convert that to what would be:

char** args = { "-n", "file", "-m", "-o", "output", 0 };

A function like:

char** build_arg_array(const char* cmd_line); 

EDIT:
Thanks for the responses. Looks like there isn’t a one step function that does the above already.

  • 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-29T22:34:19+00:00Added an answer on May 29, 2026 at 10:34 pm

    On Unix-like systems, it is the shell that does the argument parsing. So your shell will apply all of its argument splitting, wildcard expansion, quoting, and redirection logic, generate the array of arguments, fork a new process, and call execve (or one of the other exec variants) with the results of its parsing.

    So no, there isn’t a standard library call to parse arguments the way that the shell does, as that logic is implemented in the shell, not in the standard library. You can call system or popen, which are wrappers around fork and exec to run a shell command with a string, or you could call out to the shell yourself using fork and exec.

    Of course, then you have all of the problems of passing potentially untrusted input to a shell, and you would have to devise a way of communicating the results back to your parent process, perhaps using popen to open a pipe to read the results of the command you launch, which prints null-delimited arguments to standard out.

    Other than that, if you don’t want to spawn a new process and just want to parse the arguments within your program, you will have to implement your own parser.

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

Sidebar

Related Questions

Don't know how to google for such, but is there a way to query
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I don't understand why this code doesn't work: function Messages(type,text) { console.log(In function Message);
Don't overthink this - there's a very commonly used term and I ... have
Don't ask why, but is there any way to suppress a failed linking error?
Don't know if this is an eclipse specific problem but whenever I declare a
Don't know if it's I'm doing it wrong or if there's a bug (I
I don't know if this has been asked before, but what i'd like to
I don't like Jackson. I want to use ajax but with Google Gson. So

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.