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[ ...
随机推荐
- Neuroaesthetics神经美学
欢迎您到脑科学的世界! 神经美学(或neuroaesthetics)是一个相对较新的经验主义美学的子学科.经验主义美学需要科学的方法来研究艺术和音乐的审美观念. neuroesthetics于2002 ...
- Java-->利用URL类下载图片
--> 通过get 请求访问图片地址,将通过服务器响应的数据(即图片数据)存到本地文件中... --> HttpURLConnectionUtil 工具类 package com.drag ...
- UVA 572
这是一道纯正的深度优先搜索题目. 题目要求在有多少个不同的块,而不同块的定义则是,一个块中的任意一点和l另一个块中的任意一点不会相连,而相连的定义则是 在横向.纵向和对角线上相连. #include& ...
- UVa 二叉树重建(先序+中序求后序)
题意是给出先序和中序,求出后序. 先序遍历先访问根结点,通过根结点可以在中序中把序列分为左子树部分和右子树部分,我建了一个栈,因为后序遍历最后访问根结点,所以把每次访问的根结点放入栈中.因为后序遍历先 ...
- c# winform 关闭窗体时同时结束线程实现思路
Thread th = new Thread(Excute); th.IsBackground = true;这样就解决问题了. 这个属性的意思就是把线程设置为后台线程. 然后关闭进程的同时,线程也会 ...
- Yii2.0中文开发向导——Yii2中多表关联查询(join、joinwith)
我们用实例来说明这一部分 表结构 现在有客户表.订单表.图书表.作者表, 客户表Customer (id customer_name) 订单表Order (id order_ ...
- web项目引用Java项目,连接报错error HTTP Status 500 - Servlet execution threw an exception
错误信息 项目背景: 一个web项目引用一个java Project,项目中添加了引用,但是打开页面访问,总报500错误.提示:servlet初始化错误. 环境:Eclipse luna JDK: 1 ...
- python---sys
简介 sys模块用于提供对python解释器的相关操作 sys.argv 命令行参数List,第一个元素是程序本身路径 sys.modules 返回系统导入的模块字段,key是模块名,value是模块 ...
- Android无法收到指定广播的问题总结
首先是应用中不能只有一个广播,必须有一个activity或者service(这种情况比较复杂参考http://www.cnblogs.com/welcoming/p/4120497.html) 简单的 ...
- 【学】CSS3的3D动画 ——3D旋转之骰子样式的钟表(2)上
这个是3D旋转的进阶版,是一个类似与骰子的正方体.这个版本只有秒数的个位数,还没有写整个钟表,下面那个版本好好想想该怎么写 这个效果需要用到transform-style: preserve-3d. ...