Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone show me whats wrong with this program Im just trying to read from 1 file to another. I can only use systems calls

Can someone show me whats wrong with this program Im just trying to read from 1 file to another. I can only use systems calls for files.

#include < stdlib.h > #include < stdio.h > #include < unistd.h > #include < fcntl.h > #define BUFSIZE 100 #define PERM 0766

int convert_copyfile(const char * name1, const char * name2);

int main() { convert_copyfile("C:\Users\\Desktop\a.txt", "C:\Users\DevinBS\Desktop\Cpfile.txt"); int fd = open("C:\Users\\Desktop\Cpfile.txt"); printf("fd = %d ", fd); return 0; }

int convert_copyfile(const char * name1, const char * name2) { int infile, outfile; size_t nread; char buffer[BUFSIZE]; if ((infile = open(name1, O_RDONLY)))---1) //read file 100 bytes at a time { return ( - 1); } if ((outfile = open(name2, O_WRONLY | O_CREAT | O_TRUNC, PERM))--1) //if file exist write to only, if not creates empty file { close(infile); return (-2); } } while (nread = read(infile, buffer, BUFSIZE) > 0) //read from infile(source file) into buffer then write contents to outfile(target file) { if (write(outfile, buffer, nread) < nread) { close(infile); close(outfile); return ( - 3); } }

close(infile); close(outfile);

if (nread == -1) return ( - 4); }

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

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions

Question

Write the numeral as a Roman numeral. 46,281

Answered: 1 week ago

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago