#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, const char *argv[])
{
#if 0
//行号
FILE *fp;
if(argc != 2){
printf("input error!\n");
printf("usage:./a.out filename");
return -1;
}
if((fp = fopen(argv[1],"r")) == NULL){
perror("fopen error");
return -1;
}
char s[256];
int count = 0;
while(fgets(s,sizeof(s),fp) != NULL){
count++;
}
printf("该文件的行数:%d\n",count);
fclose(fp);
#endif
#if 1
//拷贝
FILE *srcfp;
FILE *dstfp;
if(argc != 3){
printf("input error!\n");
printf("usage:./a.out srcfilename dstfilename");
return -1;
}
if((srcfp = fopen(argv[1],"r")) == NULL){
perror("srcfopen error");
return -1;
}
if((dstfp = fopen(argv[2],"w")) == NULL){
perror("dstfopen error");
return -1;
}
char s[256];
while(fgets(s,sizeof(s),srcfp) != NULL){
fputs(s,dstfp);
}
fclose(srcfp);
fclose(dstfp);
printf("拷贝成功\n");
#endif
return 0;
}
IO(day 1)
于 2023-08-15 21:09:15 首次发布