69,372
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
FILE *in, *out;
char ch;
if (argc != 3)
{
fprintf(stderr, "filename source target...\n");
exit(EXIT_FAILURE);
}
if ((in = fopen(argv[1], "rb")) == NULL)
{
fprintf(stderr, "Can't open %s \n", argv[1]);
exit(EXIT_FAILURE);
}
if ((out = fopen(argv[2], "wb")) == NULL)
{
fprintf(stderr, "Can't open %s \n", argv[1]);
exit(EXIT_FAILURE);
}
while ((ch = getc(in)) != EOF)
{
putc(ch, out);
}
fclose(in);
fclose(out);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
//#include <console.h> /* Macintosh adjustment */
int main(int argc, char *argv[])
{
int byte;
FILE * source;
FILE * target;
// argc = ccommand(&argv); /* Macintosh adjustment */
if (argc != 3)
{
printf("Usage: %s sourcefile targetfile\n", argv[0]);
exit(EXIT_FAILURE);
}
if ((source = fopen(argv[1], "rb")) == NULL)
{
printf("Could not open file %s for input\n", argv[1]);
exit(EXIT_FAILURE);
}
if ((target = fopen(argv[2], "wb")) == NULL)
{
printf("Could not open file %s for output\n", argv[2]);
exit(EXIT_FAILURE);
}
while ((byte = getc(source)) != EOF)
{
putc(byte, target);
}
if (fclose(source) != 0)
printf("Could not close file %s\n", argv[1]);
if (fclose(target) != 0)
printf("Could not close file %s\n", argv[2]);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
FILE *in, *out;
char sData[32] = {0};
int iRet = 0;
if (argc != 3)
{
fprintf(stderr, "filename source target...\n");
exit(EXIT_FAILURE);
}
if ((in = fopen(argv[1], "rb")) == NULL)
{
fprintf(stderr, "Can't open %s \n", argv[1]);
exit(EXIT_FAILURE);
}
if ((out = fopen(argv[2], "wb")) == NULL)
{
fprintf(stderr, "Can't open %s \n", argv[2]);// argv[1] -> argv[2]
exit(EXIT_FAILURE);
}
while (true)// 读完整个文件
{
iRet = fread(sData, 1, sizeof(sData), in);
if (iRet == 0)
break;
fwrite(sData, 1, iRet, out);
}
fclose(in);
fclose(out);
return 0;
}