将args传递给main() [英] Passing args to main( )

查看:91
本文介绍了将args传递给main()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将参数传递给我的C程序的main()函数。

目前,我正在使用


main(char * args)


但是当我尝试打印args时,我得到一个未处理的异常错误。

有更好,更安全的方式将args传递给main(来自另一个[python]

模块)?

I want to pass arguments to the main( ) function of my C program.
Currently, I''m using

main(char * args)

But when I try to print args, I get an unhandled exception error. Is
there a better, safer way to pass args to main (from another [python]
module) ?

推荐答案

ern写道:
我想将参数传递给我的C程序的main()函数。
目前,我正在使用

main(char * args)

但是当我尝试打印args时,我得到一个未处理的异常错误。是否有更好,更安全的方式将args传递给main(来自另一个[python]
模块)?
I want to pass arguments to the main( ) function of my C program.
Currently, I''m using

main(char * args)

But when I try to print args, I get an unhandled exception error. Is
there a better, safer way to pass args to main (from another [python]
module) ?



只有两个可移植签名(模数同义词) )对于C中的main()

函数:

int main(void)/ *不带参数* /





int main(int argc,char ** argv)/ *带参数* /


其他任何东西都是非 - 标准。


HTH,

- g


-

Artie Gold - 德克萨斯州奥斯汀
http://goldsays.blogspot.com

你不能亲吻*除非你错过**

[* - 保持简单,愚蠢。 ** - 简单,愚蠢。]


There are only two portable signatures (modulo synonyms) for the main()
function in C:

int main(void) /* taking no arguments */

or

int main(int argc, char **argv) /* with arguments */

Anything else is non-standard.

HTH,
--ag

--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com
"You can''t KISS* unless you MISS**"
[*-Keep it simple, stupid. **-Make it simple, stupid.]


ern写道:
ern wrote:
我想将参数传递给main()我的C程序的功能。
目前,我正在使用

main(char * args)

但是当我尝试打印args时,我得到了一个未处理的异常错误。是否有更好,更安全的方法将args传递给main(来自另一个[python]
模块)?
I want to pass arguments to the main( ) function of my C program.
Currently, I''m using

main(char * args)

But when I try to print args, I get an unhandled exception error. Is
there a better, safer way to pass args to main (from another [python]
module) ?




唯一可移植的方式将参数传递给`main`将其声明为:


int main(int argc,char * argv [])


并传递东西在命令行上。从你的帖子来看,你很容易就能做到这一点。


BTW,`argc`给你通过的参数总数,和`argv`

是指向包含它们的字符串的指针数组。请记住,

程序名始终是第一个参数。如何以及其他

参数的外观取决于您的特定系统。标准确实

没有指明这一点,因此它在这里是偏离主题的。你最好

询问特定于你的

环境的小组中的那部分问题。


-

BR,弗拉基米尔


如果你在早餐前做了六件不可能完成的事情,为什么不回合

关闭在Milliway's餐厅吃晚餐,

宇宙结束时的餐厅?"



The only portable way of passing arguments to `main` is declaring it as:

int main(int argc, char *argv[])

and pass things on the command line. Judging by your post, you''d be
easily able to do it.

BTW, `argc` gives you the total number of arguments passed, and `argv`
is an array of pointers to strings containing them. Keep in mind that
program name is always the first argument. How it, as well as how other
arguments look like depends on your particular system. Standard does
not specify this, and hence it''s off-topic here. You''re better off
asking that part of the question in the group specific to your
environment.

--
BR, Vladimir

"If you''ve done six impossible things before breakfast, why not round
it off with dinner at Milliway''s, the restaurant at the end of the
universe?"


2006-03 -03,ern< er ******* @ gmail.com>写道:
On 2006-03-03, ern <er*******@gmail.com> wrote:
我想将参数传递给我的C程序的main()函数。
目前,我正在使用

main(char * args) )

但是当我尝试打印args时,我得到一个未处理的异常错误。是否有更好,更安全的方式将args传递给main(来自另一个[python]
模块)?
I want to pass arguments to the main( ) function of my C program.
Currently, I''m using

main(char * args)

But when I try to print args, I get an unhandled exception error. Is
there a better, safer way to pass args to main (from another [python]
module) ?




main(int argc, char * argv [])



main(int argc, char *argv[])


这篇关于将args传递给main()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆