Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
226 views
in Technique[技术] by (71.8m points)

Command-line Parameters in C program?

How do I read command-line parameters in C? For example, in

./test --help

or

./test --build

how do I access "--build" or "--help"?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your parameters are in argv:

int main(int argc, char **argv)

if you printf the content of argv (argv[0],argv[1] etc) youll get the idea.

try:

int main (int argc, char **argv)
{
    for(int i = 0;i< argc;i++) 
        printf("%s
",argv[i]);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...