How to pass command line arguments to a c program(如何将命令行参数传递给 c 程序)
问题描述
自从我学会编程以来,我就知道如何编写一个接受命令行参数的程序.我不明白的是这些参数如何获得它们的值.希望我没有将这两者混为一谈,但是参数和参数之间是有区别的.argument 是函数被调用时赋予的值,例如: foo( a, b, c);其中 a、b 和 c 是值.参数是调用时函数内部的值.
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
主要功能如下:
int main (int argc, char *argv[])
这篇关于如何将命令行参数传递给 c 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将命令行参数传递给 c 程序


基础教程推荐
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 这个宏可以转换成函数吗? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01