我在 c 中有这段代码来打开文件并将其内容写入另一个文件,但是当我运行它时结果错误并且某些行只复制并进入无限循环:
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
//static int read_cnt;
//static char *read_ptr;
//static char read_buf[1024];
int main(int argc, char **argv)
{
//i have a variable size which is an int and is the byte size of the file
//i got the byte size of file from stat
int fileread = open("/tmp/des.py",'r');
char buffer[1024];
while((fileread = read(fileread, buffer, sizeof(buffer))>0));
{
if(fileread < 0)
printf("error write");
}
int filewrite = open("/tmp/original.txt", O_WRONLY|O_CREAT);
while ((filewrite = write(filewrite, buffer, sizeof(buffer))>0))
{
if(filewrite < 0)
printf("error write");
}
close(filewrite);
close(fileread);
return 0;
}
那么如何解决这个问题