//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; }

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

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

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

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.