文件输入输出问题
#include<stdio.h>#include<stdlib.h>
int main(int argc,char*argv[])
{
int ch;
FILE *fp;
long count=0;
if(argc!=3)
{
printf("usage:%sfilename\n",argv[0]);
exit(1);
}
if((fp=fopen(argv[1],"r"))==NULL) //从这句开始我就看不懂了哦,麻烦详细解释一下,我删了后面的代码程序照样有用了
{
printf("can't open %s\n",argv[1]);
exit(1);
}
while((ch=getc(fp))==EOF)
{
putc(ch,stdout);//相当于putchar(ch);
count++;
}
fclose(fp);
printf("file %s has %ld characters\n",argv[1],count);
return 0;
}