_____main函数含有 两个参数 ,argc ,argv[]

这两个参数用以指示命令行输入的参数信息。

argc 的值是输入的参数的数量。argv是一个数组,每个数组元素指向一个string字符串类型的数据的地址,也就是存放每一个输入参数的地址。argv就是 char ** 类型。

void fileCopy(FILE *ifp,FILE *ofp)
{
int c;
while( (c = getc(ifp) ) != EOF)
{
putc(c,ofp);
} }
int main(int argc, char *argv[])
{ //practice file access
//practice argc, argv
FILE *fp;
if(argc == ) //no args;copy standard input
{
fileCopy(stdin, stdout);
}
else
{
printf("%d\n",argc);
while(--argc > )
{
int i;
for(i = ; i < argc; i++) //parameter is a string.
{
printf("%s%s",argv[i],(i < argc - ) ? " " :""); }
printf("\n");
/* when parameter is a file name.
if( (fp = fopen(*++argv,"r")) == NULL)
{
printf("can't open %s\n", *argv);
return 1;
}
else
{
fileCopy(fp,stdout);
fclose(fp);
}
*/
}
}
return ;
}

___file access

为了对一个文件进行存取操作,首先吸引获得这个文件的指针,这个文件指针指向一个结构类型数据,它包含了所关联文件的相关信息,包括buffer的位置,文件中当前的编辑位置,等等。用户不需要知道那些信息的细节。只需要利用库函数中结构类型FILE,只需做如下操作

FILE *fp;
//the open operation may not successfully, check is necessary
if( (fp = fopen(FILE_NAME,MODE) == NULL )
{
fprintf(stderr, "can'topen%s\n",FILE_NAME);
exit(EXIT_FAILURE);
} //after file operation, close the file
fclose(fp);

_ fprintf, fscanf 对应于标准输入输出的printf和scanf,参数多了最前面的一个FILE类型的参数。

_ fputs, fgets,   simillar to the getline function

_ fread, fwirte  has same parameters. They allow big block access to file in one step.

make sure the file position is your wanted. use eg:

rewind(fp);//set file postion at the start. !!!! reset the file postion is important

There are other liarbry functions to set file positon.

___存取的文件类型可以是二进制类型,或者是text类型的,eg,file.bat , or file.txt.

text类型的文件操作时容易出问题,比如回车键之类可能会出题,对text操作有危险。

用fprintf 能在text文件中直接看到数值,但是呢

file access , argc, argv[ ]的更多相关文章

  1. 命令行参数(argc, argv)

    每个C语言程序都必须有一个称为main()的函数,作为程序启动的起点.当执行程序时,命令行参数(command-line argument)(由shell逐一解析)通过两个入参提供给main()函数. ...

  2. C关键字typedef及argc,argv,env参数含义

    C关键字typedef--为C中各种数据类型定义别名. 在此插一点C知识 int main(int argc,const char *argv[],const char *envp[])主函数的红色部 ...

  3. c语言argc argv

    转载自 http://blog.csdn.net/yukiooy/article/details/4682989 main(int argc,char *argv[ ]) argv为指针的指针 arg ...

  4. Main函数中的参数argc,argv的使用简单解析

    本篇文章是对Main函数中的参数argc,argv的使用进行了简单的分析介绍,需要的朋友参考下: C/C++语言中的main函数,经常带有参数argc,argv,如下:  int main(int a ...

  5. Method and system for implementing mandatory file access control in native discretionary access control environments

    A method is provided for implementing a mandatory access control model in operating systems which na ...

  6. Unable to copy file, Access to the path is denied

    Unable to copy file, Access to the path is denied http://stackoverflow.com/questions/7130136/unable- ...

  7. Samba set of user authentication and file access rights

    This series is compatible with Linux certification exam LPIC. A typical Linux user-level topics omit ...

  8. px4::init_once();和px4::init(argc, argv, "px4");函数学习

    px4::init_once(); void init_once() { _shell_task_id = pthread_self();                                ...

  9. c语言中命令行参数argc,argv[]详解

    main(int argc,char *argv[ ]) 1.argc为整数 2.argv为指针的指针(可理解为:char **argv or: char *argv[] or: char argv[ ...

随机推荐

  1. mysql -workbench : Error cause by ' sql-mode = only-full-group-by'

    当mysql出现"only-full-group-by"问题时,是mysql的sql_mode设置出现了问题. 解决: 1.  找到mysql的 my.cnf文件,我的文件路径是: ...

  2. HTML标签小记

    <body> </body>标签,网页内容放在这里 <p> </p>标签,网页的段落 <hx> </hx>标签,网页的标题 &l ...

  3. CF 628B New Skateboard --- 水题

    CD 628B 题目大意:给定一个数字(<=3*10^5),判断其能被4整除的连续子串有多少个 解题思路:注意一个整除4的性质: 若bc能被4整除,则a1a2a3a4...anbc也一定能被4整 ...

  4. 安装初始化mysql后,默认几个库介绍

    背景介绍:  当我们安装初始化mysql后,默认建了几个数据库,那么这些数据库有什么作用呢?mysql> show databases;+--------------------+| Datab ...

  5. How to relocate tablespace directory

    I’ll demonstrate how to relocate a tablespace directory without the reconstruction of databases. I h ...

  6. ABBYY FineReader自定义工作区的方法

    ABBYY FineReader作为一款OCR图文识别软件,界面具有用户友好性和直观性,以结果为导向,可以在不进行任何其他培训的情况下使用该程序,新用户可以迅速掌握主要功能,轻松自定义程序的界面,接下 ...

  7. linux项目-之系统安装部署-cobbler

    http://cobbler.github.io/manuals/2.6.0/1/1_-_Release_Notes.html http://www.osyunwei.com/archives/760 ...

  8. 【MySQL】结构行长度的一些限制

    今天被开发提交的DDL变更再次困惑,表中字段较多,希望将已有的两个varchar(4000)字段改为varchar(20000),我想innodb对varchar的存储不就是取前768字节记录当前行空 ...

  9. 【MySQL】优化—工欲善其事,必先利其器之EXPLAIN

    接触MySQL已经有一段时间了,了解如何优化它也迫在眉睫了,话说工欲善其事,必先利其器.最近我就打算了解下几个优化MySQL中经常用到的工具.今天就简单介绍下EXPLAIN. 环境准备 Explain ...

  10. JavaScript中 Promise的学习以及使用

    今天一个哥们发过来一段js代码,没看懂,就顺便学习了一下,代码如下  Promise.resolve('zhangkai').then(value => {console.log(value)} ...