File Copy Homework, 4 november, 2010
3 posters
IITDU Forum :: Academics (BIT) :: Semester 4 :: CSE 401
Page 1 of 1
File Copy Homework, 4 november, 2010
This is the copy homework which is supposed to submitted today.
Its in C.
Hope you will not just copy and paste.
Its in C.
- Code:
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
int main(int args, char* arg[]){
if (args < 4){
puts("To few arguments");
return args;
}else if(args > 4){
puts("To many arguments");
return args;
}
char buffer[1024];
size_t nbytes = atoi(arg[3]);
ssize_t readByte, writeByte;
int writeFile,readFile;
readFile = open(arg[1], O_RDONLY);
if(errno!=0){
printf("Exit with error code %d\n", errno);
printf("\tCould not open file %s\n", arg[1]);
return errno;
}
readByte = read(readFile, buffer, nbytes);
if(errno!=0){
printf("Exit with error code %d\n", errno);
printf("\tCould not read file %s\n", arg[1]);
close(readFile);
return errno;
}
if(readByte==-1){
printf("Exit with error code %d\n", readByte);
printf("Nothing to read\n");
close(readFile);
return errno;
}
writeFile = open(arg[2], O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if(errno!=0){
printf("Exit with error code %d\n", errno);
printf("\tCould not open file: %s\n", arg[2]);
return errno;
}
writeByte = write(writeFile, buffer, nbytes);
if(errno!=0){
printf("Exit with error code %d\n", errno);
printf("\tCould not write to file: %s\n", arg[2]);
close(writeFile);
return errno;
}
if(writeByte==-1){
printf("Exit with error code %d\n", writeByte);
printf("\tNothing to write\n");
close(writeFile);
return errno;
}
close(readFile);
close(writeFile);
return 0;
}
Hope you will not just copy and paste.
BIT0102-Mohaimin- Programmer
- Course(s) :
- BIT
Blood Group : B+
Posts : 415
Points : 715
BIT0119-Asif- Study Moderator
- Course(s) :
- BIT
Blood Group : B+
Posts : 163
Points : 432
Re: File Copy Homework, 4 november, 2010
C দিয়ে করলে কি হবে???
BIT-0126- Alpha Release
- Course(s) :
- BIT
Blood Group : AB+
Posts : 43
Points : 68
Similar topics
» DSD exam 5 November : Syllabus
» Usefull links for OS assignment: Make your own copy function
» Combined class routine(draft copy) given by kabir sir
» Text Copy Problem in Ubuntu from closed window : Solved!
» Creating JAR file
» Usefull links for OS assignment: Make your own copy function
» Combined class routine(draft copy) given by kabir sir
» Text Copy Problem in Ubuntu from closed window : Solved!
» Creating JAR file
IITDU Forum :: Academics (BIT) :: Semester 4 :: CSE 401
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Tue Sep 29, 2015 2:45 pm by Sophiawood
» Cisco EHWIC SFP/GE WAN Card
Mon Sep 07, 2015 11:08 am by Sophiawood
» Huawei S1700-28GFR-4P-AC Price
Thu Jun 25, 2015 2:31 pm by Sophiawood
» teach yourself C++ / Herbert Schildt Solutions
Wed Jun 03, 2015 1:52 pm by Abdullah Al Noman
» teach yourself c by herbert schildt pdf
Wed May 13, 2015 11:01 pm by Raquib Ridwan
» ASA 5506X With Firepower ASA5506-K9
Fri Apr 10, 2015 4:31 pm by Sophiawood
» New Trends in Deal Business
Tue Feb 03, 2015 9:38 pm by nersoa
» PoE Power Allocation for WS-C2960S-24PS-L
Wed Nov 05, 2014 11:12 am by Sophiawood
» How to cure back pain
Fri Oct 31, 2014 7:15 pm by Bergen Guildford