如何通过命令行参数C程序 [英] How to pass command line arguments to a c program
问题描述
我知道如何编写的程序接受的命令行参数自从我学会了编程。我不明白的是,这些参数是如何得到他们的价值观。但愿我没有这两个混在一起,但有一种说法和参数之间的差异。一个的参数的是给函数的值时,它被称为如:美孚(A,B,C);其中a,b,和c是值。 A 参数是其内部的功能,而被调用的值。
I've known how to write a program that accepts command line arguments ever since I learned to program. What I don't understand is how these parameters get their values. Hopefully I don't have these two mixed up but there is a difference between an argument and a parameter. An argument is the value given to the function when it is called such as: foo( a, b, c); where a, b, and c are the values. A parameter is the values that are inside the function while is being called.
所以我的问题是怎样的一个人通过命令行的参数的一个程序?我知道如何读的论点,即 ARGC
是参数的个数,的argv
是一个指向数组包含有参数,等等,等等,但我只是不知道如何给这些参数的值..串
So my question is how does a person pass command line arguments to a program? I understand how to read the arguments, that argc
is the number of arguments, argv
is a pointer to an array of strings containing the arguments, etc. etc. but I just don't know how to give those arguments a value..
我在寻找为C和C ++的信息。我还算是一个新手在此。
I'm looking for information for both C and C++. I'm sort of a novice at this.
推荐答案
在Windows环境中,你只是通过他们,像这样在命令行上:
In a Windows environment you just pass them on the command line like so:
myProgram.exe arg1 arg2 arg3
ARGV [1]包含ARG1等
argv[1] contain arg1 etc
主要职能将是以下内容:
The main function would be the following:
int main (int argc, char *argv[])
这篇关于如何通过命令行参数C程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!