file copy
(高顯忠, sjgau4311@gmail.com, 2011-04-19 11:13)
1樓
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
using namespace std;
// --------------------------------------------------------
int main(int argc, char *argv[])
{
// for filecopy aaa.txt bbb.txt
// fgetc(), fputc()
FILE *f1, *f2;
if (argc != 3) {
printf("\n Usage: VC0419 aaa.txt bbb.txt [Enter] \n");
system("pause");
exit(1);
}
if ((f1= fopen(argv[1], "rb")) == NULL) {
printf("\n for read, fopen() error for %s \n", argv[1]);
system("pause");
exit(1);
}
if ((f2= fopen(argv[2], "wb")) == NULL) {
printf("\n for write, fopen() error for %s \n", argv[1]);
system("pause");
exit(1);
}
printf("\n ***, 2- fopen() OK! \n");
system("pause");
// --------------------------------------------------------------
int ch1= fgetc(f1), ct1= 0;
while (ch1 != EOF) {
fputc(ch1, f2);
ct1++;
ch1= fgetc(f1);
}// end while()
printf("\n ct1= %d \n", ct1);
system("pause");
return 0;
}// end of main()