C语言文件操作 简单的文件读写加外部调用

来源:互联网 发布:淘宝网运动女装夏装 编辑:程序博客网 时间:2024/06/06 05:19
/**cmd.exe*test.exe "c:/log.log" "c:/log2.log"*/#include <stdio.h>int main(int argc, char *argv[]){FILE *fp;FILE *fp2;char ch;printf("%s\n", argv[1]);if((fp=fopen(argv[1], "rt")) == NULL){printf("first Cannot open file strike any key exit!");getch();exit(1);}if((fp2=fopen(argv[2], "wt")) == NULL){printf("second Cannot open file strike any key exit!");getch();exit(1);}ch = fgetc(fp);while(ch!=EOF){//putchar(ch);/*回显到屏幕*/fputc(ch, fp2);/*文件写入*/ch=fgetc(fp);}getchar();fclose(fp);}