c - read() and write() functions do not collaborate -



c - read() and write() functions do not collaborate -

the task re-create sentence 1 file , reverse meanwhile.

there no errors while compiling, original file contains sentence reverse 1 not save in sec file.

thanks in advance help.

here code:

#include <stdio.h> #include <fcntl.h> #include <errno.h> int main(int argc, char* argv[]) { int file1 = open("a.txt", o_creat | o_rdwr | o_trunc, 0777); write(file1, "how you?", 12); lseek(file1, -1, seek_end); //////////////////////////////// char c; int file2 = open("b.txt", o_creat | o_rdwr | o_trunc, 0777); while( read(file1, &c, 1) ) { write(file2, c, 1); lseek(file1, -1, seek_cur); } //////////////////////////////// close(file1); close(file2); homecoming 0; }

i changed while loop this:

int = 0; while( read(file1, &c, 1) ) { i++; write(file2, &c, 1); lseek(file1, -2, seek_cur); if(i==12) // 12 length of file beingness read. break; }

and included this:

#include <sys/types.h> #include <unistd.h>

works @ side.

c linux

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -