私はファイルを開いてその内容を別のファイルに書き込むために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;
}
では、この問題を解決する方法