//using I/O to copy one file to another file #include<fcntl.h> #include<stdio.h> #include<unistd.

h> int main(int c, const char * fn[]) { char ch; int fd1 = open(fn[1],O_RDONLY); int fd2 = open(fn[2],O_WRONLY); int count = 1; int a; while(count=read(fd1,&ch,1) != 0) { a = write(fd2,&ch,1); } if (a>0) { printf("Write success\n"); } else { printf("fail"); } return 0; }

} return 0. int fd2 = open(fn[2]. while(count=read(fd1.1) != 0) { st[i]=ch. printf("\n%s". i=0.O_RDONLY). char copy[BUFSIZ]="\0". } st[i]='\0'.&copy. } . printf("\nNumber of alphabet= "). a.O_WRONLY).//copy file to another file using I/O in reverce order #include<fcntl. } a = write(fd2.h> #include<stdio. while (i!= -1) { cpy[j++]=st[--i].h> int main(int c. printf("\n"). j=0.h> #include<unistd. printf("\n"). if (a>0) { printf("\nreverse Data"). int int int int int count = 1. const char * fn[]) { char ch. i++. printf("%d". int fd1 = open(fn[1]. } else { printf("fail"). k++. k=0.i). char st[BUFSIZ]="\0".copy).&ch.k).

//printf("buffer size: %d\n".buff1)."r").buff2). fclose(p). } . fclose(q)."a"). q=fopen("/home/aimy/aiman/aa.//using library to one file copy to another file in revers order #include<stdio. printf("\n %s". char buff1[BUFSIZ].buff2[BUFSIZ].buff2).q). //printf("file cannot open/n"). sizeof(buff1)). return 0.txt".*q. while(fgets(buff1.p)!=NULL) fputs(buff1. setbuf(q. setbuf(p.h> int main() { FILE *p.txt".BUFSIZ. p=fopen("/home/aimy/aiman/texta.

a=statbuff. q=fopen("/home/aimy/aiman/aa. return 0. stat("/home/aimy/aiman/texta. int a . printf(" \n%c".h> #include<sys/stat. fseek(p. *q. p=fopen("/home/aimy/aiman/texta.SEEK_CUR).//copy one file to another file in reverse order using using library #include <stdio.h> #include <stdlib.SEEK_END). } . fputc(c.txt".-2.buff2).txt". char c.h> int main() { FILE *p.buff1)."a"). char buff1[BUFSIZ]. char buff2[BUFSIZ]. struct stat statbuff. fclose(q).st_size. setbuf(q.txt".c). } fclose(p).q).-1.h> #include<unistd."r"). setbuf(p. fseek(p. a--. &statbuff). while(a!=0){ c = fgetc(p).

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.