How would I go about printing contents of a file that I've appended to using only low-level I/O functions?
The closest I get is printing the text that I'm using to append Example:
file1.txt = dog
file2.txt = cat
I want file2.txt, which is now "catdog" to be printed out. How would I do that?
As said before I can only get "dog" to print. I'm also successful in appended the file. I know it's probably really simple solution but I been scratching my head for hours.
My code
while (1) {
if ((bufchar = read(fdin1, buf, sizeof(buf))) > 0) {
bp = buf; // Pointer to next byte to write.
while (bufchar > 0) {
if ((wrchar = write(fdin2, bp, bufchar)) < 0)
perror("Write failed");
bufchar -= wrchar; // Update.
bp += wrchar;
}
}
else if (bufchar == 0) { // EOF reached.
break;
}
else
perror("Read failed");
}