Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!