file access , argc, argv[ ]
时间:2021-07-01 10:21:17
帮助过:5人阅读
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 ==
1)
//no args;copy standard input
{
fileCopy(stdin, stdout);
}
else
{
printf("%d\n",argc);
while(--argc >
0)
{
int i;
for(i =
0; i < argc; i++
) //parameter is a string.
{
printf("%s%s",argv[i],(i < argc -
1) ?
" " :
"");
}
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 0;
}
___file access
fprintf, fscanf 对应于标准输入输出的printf和scanf,参数多了最前面的一个FILE类型的参数。
FILE类型
file access , argc, argv[ ]
标签: