file access , argc, argv[ ]
_____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[ ]的更多相关文章
- 命令行参数(argc, argv)
每个C语言程序都必须有一个称为main()的函数,作为程序启动的起点.当执行程序时,命令行参数(command-line argument)(由shell逐一解析)通过两个入参提供给main()函数. ...
- C关键字typedef及argc,argv,env参数含义
C关键字typedef--为C中各种数据类型定义别名. 在此插一点C知识 int main(int argc,const char *argv[],const char *envp[])主函数的红色部 ...
- c语言argc argv
转载自 http://blog.csdn.net/yukiooy/article/details/4682989 main(int argc,char *argv[ ]) argv为指针的指针 arg ...
- Main函数中的参数argc,argv的使用简单解析
本篇文章是对Main函数中的参数argc,argv的使用进行了简单的分析介绍,需要的朋友参考下: C/C++语言中的main函数,经常带有参数argc,argv,如下: int main(int a ...
- 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 ...
- 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- ...
- 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 ...
- px4::init_once();和px4::init(argc, argv, "px4");函数学习
px4::init_once(); void init_once() { _shell_task_id = pthread_self(); ...
- c语言中命令行参数argc,argv[]详解
main(int argc,char *argv[ ]) 1.argc为整数 2.argv为指针的指针(可理解为:char **argv or: char *argv[] or: char argv[ ...
随机推荐
- springboot系列之-helloword入门
一. What: Spring Boot是什么?以1.4.3.RELEASE为例,官方介绍为:http://docs.spring.io/spring-boot/docs/1.4.3.RELEASE/ ...
- .vimrc常用
vim 的環境設定參數 :set nu:set nonu 行号 :set tabstop=4 :set softtabstop=4 :set shiftwidth=4 tab :set hlsea ...
- PHP curl传 json字符串
$ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_seto ...
- poj3114 强连通+最短路
题意:有 n 个城市,城市之间能够通过邮件或者电子邮件传递消息,已知 m 条邮件线路,每条线路代表 A 能送邮件到 B,并且花费 V 时间,如果几个城市之间能够相互邮件送达,那么他们就在同一个国家内, ...
- VS2013添加使用lib的方法
使用第三方厂家的库,一般都会有三个文件: xxx.h xxx.lib xxx.dll 头文件很明显,就在需要用到的文件里面include就好. lib文件,可以直接在IDE中添加,具体步骤有两个: 1 ...
- morhia解决BigDecimal映射问题
错误信息:morphia No usable constructor for java.math.BigDecimal 解决办法:增加自定义类型转换器,代码如下 package cn.huilink. ...
- Java 学习总结(一)
1. 概述 1.1 dos命令行--常见的命令 l dir : 列出当前目录下的文件以及文件夹 l md : 创建目录 l rd : 删除目录 l cd : 进入指 ...
- Windows xp IIS显示403错误解决方案
XP的IIS很烦人,很多限制. 最近一客户用XP安装IIS,总提示:403.9 错误 连接的用户过多 解决方案: 1)安装IIS配置工具 下载地址:http://download.microsoft. ...
- oracle 如何查询过去某个时间点的记录(应用于某个时间点的误操作,回滚到之前的操作)
这个功能是在自己误操作,将某些数据更改错了,你想恢复更改错之前的数据,这个时候你可以使用这种方式 不过建议要小心更改数据,如果实在有必要去更新,请先备份数据表,不到万不得以才可以这么做. SE ...
- Token验证失败
Token验证失败 微信 微信公众平台开发 Token校验失败 URL Token原文 http://www.cnblogs.com/txw1958/p/token-verify.html Token ...