求助个文件读写问题
下面这个代码执行后,新生成的文件比源文件大,总是带个尾巴,请教各位这怎么改啊
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
int main(void)
{
int fd1, fd2;
int rsize = 0, wsize = 0;
char buf[1024];
memset(buf, 0, 1024);
if((fd1 = open("udp.txt", O_RDONLY, 777) )< 0)
{
printf("open1 error!\n");
return -1;
}
if((fd2 = open("copy.txt", O_CREAT | O_WRONLY, 777)) < 0 )
{
printf("open2 error!\n");
return -1;
}
printf("open2 ok\n");
while((rsize = read(fd1, buf, sizeof(buf))) )
{
printf("rsize = %d\n",rsize);
lseek(fd1, 0, SEEK_CUR);
wsize = write(fd2, buf, strlen(buf));
if(wsize == NULL)
{
printf("write error\n");
return -1;
}
printf("wsize = %d\n",write);
memset(buf, 0, 1024);
}
while(1);
close(fd1);
close(fd2);
}