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[ ...
随机推荐
- 快速判断ie10及以上版本浏览器
if (!(/msie [6|7|8|9]/i.test(navigator.userAgent))){ //ie10以上 }; 快速判断ie10及以上版本浏览器
- 億万笑者 - Radwimps
億万笑者 作曲:野田洋次郎 作词:野田洋次郎 明日に希望を持った者だけに 絶望があるんだ何かを信じた者だけに 裏切りはあるんだ勇者だけに与えられた 名誉の負傷とでも言うのかそれにしてはずいぶんと 割に ...
- 在Linux系统中如何设置APACHE服务器里的后台页面只允许某个IP地址访问
补充资料 本网络中使用LINUX服务器,web服务器是由APACHE搭建,IP地址为192.168.1.5,后台页面为/admin/login.jsp . 如何设置后台页面LOGIN.JSP只允许19 ...
- ajax中返回json数据有"
1.将“转义为\" string table=sb.ToString(); table.Replace("\"","\\\"");
- QSqlTableModel 使用方法(转)
Qt QSqlTableModel 使用心得 连接数据库 执行sql查询,条件显示,排序 获取记录数,列数以及记录内容,字段内容 新增,修改,删除,恢复 其它 1---------------连接数据 ...
- spring-实现配置文件读取
spring 实现配置读取 Java 的配置读取方式一般是采用java.utils.Properties 或是apache的Configuration工具:然而 spring 框架内置了配置文件的读取 ...
- SSIS 项目部署模型
微软 BI 系列随笔 - SSIS 2012 基础 - SSIS 项目部署模型 关于部署 SSIS 2012 支持两种部署模型:项目部署模型和包部署模型. 使用项目部署模型可以将项目部署到 Integ ...
- mysql按照中文名称排序
mysql按照中文名称排序 Sql代码 www.2cto.com /* Navicat MySQL Data Transfer Source Server : ...
- python(26)查看文件的大小
有时候,在写文件的时候需要判断文件的大小,或者删除空的文件 import os from os.path import join, getsize def getdirsize(dir): size ...
- 一个简单的CORBA例子
因为对CORBA分析的需要,这里写一个简单的CORBA例子.从JDK1.2开始,JDK中集成了ORB的实现,本例子使用了JDK1.7,对于JDK1.2+应该都没有问题.这个例子实现一个简单的加减乘除的 ...