_____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. Nagios NSclient Failed to get CPU value: \238(_total)\6: Failed to get mutex :(

    一台Windows Server 2012的nsclient出现以下的错误,表示无法获得CPU信息 2016-08-08 10:31:33: e:..\..\..\..\trunk\modules\C ...

  2. 创建一个maven web project

    几经周折总算是找到了和高杨学长一样的web  project的方法.感谢学长的一语点醒.我之前以为,既是maven又是web project的项目得要是通过dynamic web project转换到 ...

  3. LA 3938 动态最大连续和 线段树

    题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...

  4. linux 启动weblogic的某服务报错

    问题如标题所示, 错误信息主要包括: weblogic.store.PersistentStoreException: [Store:280073]The file store"WLS_DI ...

  5. trace工具,c++/c#/python

    下载地址: http://files.cnblogs.com/files/wjx0912/xtrace.rar 很方便的调试工具,已在c#,  vc2015, python2.7.10环境下测试. 闭 ...

  6. 使用 .bash_profile与.bashrc修改字符集

    发现终端设置为UTF8显示以后 svn打印终端就一直乱码, 是用户字符集的原因 有人建议 修改.bashrc 有人建议修改~/.bash_profile 搜索了下区别 /etc/profile:此文件 ...

  7. Spring 学习总结 使用静态工厂创建Bean

    创建Bean时,class属性必须指定,此时为静态工厂类. factory-method指定静态工厂方法名. 接口: public interface Being { public void test ...

  8. 1、java中常用名字规范

    包名:多个单词组成是所有单词字母小写. 类名.接口名:所有单词首字母大写. 变量名.函数名:多单词组成时第一个单词首字母小写,从第二个单词开始首字母大写. 常量名:所有字母大写,单词之间用 “_” 连 ...

  9. yii2 使用composer安装

    composer global require "fxp/composer-asset-plugin:~1.0.0" composer create-project --prefe ...

  10. OGNL语言

                                                             OGNL 一.概述 以下内容摘自Ognl的官网: OGNL stands for Ob ...