c语言改错:实现文件的复制,源文件名和目标文件名由命令行参数指定.
#include<stdio.h>#include<stdlib.h>intmain(intargc,char*argv[]){FILE*srcFile,*destFil...
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *srcFile, *destFile;
int ch;
/*********Found************/
if (argc == 2)//说是这改错了
{
printf("输入参数有误.\n");
exit(1);
}
/*********Found************/
if ((srcFile = fopen(argv[1], "rb")) == NULL)
{
printf("无法打开源文件 %s\n", argv[1]);
exit(2);
}
if ((destFile = fopen(argv[2], "wb")) == NULL)
{
fclose(srcFile);
printf("无法打开目标文件 %s\n", argv[2]);
exit(3);
}
while ((ch = fgetc(srcFile)) != EOF)
{
fputc(ch, destFile);
}
printf("succeful to copy a file!\n");
fclose(srcFile);
fclose(destFile);
return 0;
} 展开
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *srcFile, *destFile;
int ch;
/*********Found************/
if (argc == 2)//说是这改错了
{
printf("输入参数有误.\n");
exit(1);
}
/*********Found************/
if ((srcFile = fopen(argv[1], "rb")) == NULL)
{
printf("无法打开源文件 %s\n", argv[1]);
exit(2);
}
if ((destFile = fopen(argv[2], "wb")) == NULL)
{
fclose(srcFile);
printf("无法打开目标文件 %s\n", argv[2]);
exit(3);
}
while ((ch = fgetc(srcFile)) != EOF)
{
fputc(ch, destFile);
}
printf("succeful to copy a file!\n");
fclose(srcFile);
fclose(destFile);
return 0;
} 展开
展开全部
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *srcFile, *destFile;
int ch;
/*********Found************/
if (argc != 3)
{
printf("输入参数有误.\n");
exit(1);
}
/*********Found************/
if ((srcFile = fopen(argv[1], "rb")) == NULL)
{
printf("无法打开源文件 %s\n", argv[1]);
exit(2);
}
if ((destFile = fopen(argv[2], "wb")) == NULL)
{
fclose(srcFile);
printf("无法打开目标文件 %s\n", argv[2]);
exit(3);
}
while ((ch = fgetc(srcFile)) != EOF)
{
fputc(ch, destFile);
}
printf("succeful to copy a file!\n");
fclose(srcFile);
fclose(destFile);
return 0;
}
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *srcFile, *destFile;
int ch;
/*********Found************/
if (argc != 3)
{
printf("输入参数有误.\n");
exit(1);
}
/*********Found************/
if ((srcFile = fopen(argv[1], "rb")) == NULL)
{
printf("无法打开源文件 %s\n", argv[1]);
exit(2);
}
if ((destFile = fopen(argv[2], "wb")) == NULL)
{
fclose(srcFile);
printf("无法打开目标文件 %s\n", argv[2]);
exit(3);
}
while ((ch = fgetc(srcFile)) != EOF)
{
fputc(ch, destFile);
}
printf("succeful to copy a file!\n");
fclose(srcFile);
fclose(destFile);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询