Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6844087
  • 博文数量: 3857
  • 博客积分: 6409
  • 博客等级: 准将
  • 技术积分: 15948
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-02 16:48
个人简介

迷彩 潜伏 隐蔽 伪装

文章分类

全部博文(3857)

文章存档

2017年(5)

2016年(63)

2015年(927)

2014年(677)

2013年(807)

2012年(1241)

2011年(67)

2010年(7)

2009年(36)

2008年(28)

分类:

2011-10-27 13:28:23

今天是看到 K&R C 的书上的例题,引发了对 int main(int argc,char* argv[])的学习
 
 
第一,回显程序命令行参数
 
在 d:\ 编写 程序,并命名为 c.c
 
 
#include
int main(int argc, char ** argv)
{
    int i;
    for (i=0; i < argc; i++)
        printf("Argument %d is %s.\n", i, argv[i]);
    return 0;
}
在附件中找到命令提示符  输入 (exe文件的路径)(当然不是在编译器输入了)
 
如图所示
 
 
 
 
看到得到的结果了么~?
 
啊?argc,argv是什么也明白了吧~
 
附一段 K&R C 原话
 
In environments that support C, there is a way to pass command-line arguments or parameters to a program when it begins executing. When main is called, it is called with two arguments. The first (conventionally called argc, for argument count) is the number of command-line (注意所在位置,是WIN命令提示符中,或LINUX命令行中)arguments the program was invoked with; the second (argv, for argument vector) is a pointer to an array of character strings that contain the arguments, one per string. We customarily use multiple levels of pointers to manipulate these character strings.
 
我们都知道main是一个函数,而函数就能被调用, 但是在我们初学的时候我们怎么也不会想到去调用他(因为往往语法(比如数组指针,指针数组就)把注意力全部吸引住了)~~现在明白了,是在命令行去调用他~~~
 
 
这么一来,反过头来看一下写这篇博文的出发点~~
 
<>5.10的两个函数,就是在编辑好以后通过系统调用~~~正是第一遍学习的时候没有理解“As a second example, let us make some enhancements to the pattern-finding program from Section 4.1. If you recall, we wired the search pattern deep into the program, an obviously unsatisfactory arrangement.”的意思~~“中文版翻译:我们将查找模式内置到程序中了”

(显然有略微失真,当然全书整体翻译还是很好的~~) 

 

 

阅读(1318) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~