Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions

Question

8. Explain the relationship between communication and context.

Answered: 1 week ago