Answered step by step
Verified Expert Solution
Question
1 Approved Answer
With the C-code below, how can I use system calls to write to and file and then print out the content of that file onto
With the C-code below, how can I use system calls to write to and file and then print out the content of that file onto the screen with printf()?
//cp.c #include "types.h" #include "stat.h" #include "user.h" #include "fcntl.h" char buf[512]; int main(int argc, char *argv[]) { int fds, fdd, n; if(argc != 3) { printf(1, "cp SOURCE DEST"); exit(); } // open source file if((fds = open(argv[1], O_RDONLY)) < 0) { printf(1, "cp: cannot open %s ", argv[1]); exit(); } // open destination file if((fdd = open(argv[2], O_CREATE|O_RDWR)) < 0) { printf(1, "cp: cannot open %s ", argv[2]); exit(); } while ((n = read(fds, buf, sizeof(buf))) > 0 ) { write(fdd, buf, n); } close(fds); close(fdd); exit(); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started