I tried the following program to copy one binary file (a.txt) to another (b.txt). And found that b.txt has one extra char: 0xFF.
What is the reason?
1. source code
==============================
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
FILE *in, *out;
char ch;
if(argc != 3)
{
printf("Usage:: %s src dest\n", argv[0]);
exit(0);
}
if((in = fopen(argv[1], "rb")) == NULL)
{
printf("Cannot open file %s.", argv[1]);
exit(0);
}
if((out = fopen(argv[2], "wb")) == NULL)
{
printf("Cannot open file %s.", argv[2]);
exit(0);
}
while(!feof(in))
{
fputc(fgetc(in), out);
}
fclose(in);
fclose(out);
return 0;
}
2. a.txt and b.txt viewed in UltraEdit-32 (see picture)
=================================
[此贴子已经被作者于2007-8-23 13:15:28编辑过]