unlink

Document Sample
unlink Powered By Docstoc
					#include"stdio.h" #include"unistd.h" #include"fcntl.h" #include"sys/stat.h"
#include"sys/types.h"

int main(int a,char *b[]) { int n1,n2; char c; if(a<3) {
  printf("less arguments"); return 0;
}

n1=open(b[1],O_RDONLY); //opening first file in read mode
n2=open(b[2],O_CREAT|O_RDWR,S_IRWXU); //opening second file in write mode

if(n1==-1 || n2== -1) {
  printf("error"); return 0;
} while(read(n1,&c,1)!=0) //reading charecters in first file write(n2,&c,1); //write in
second file unlink(b[1]); //removing the first file close(n2); close(n1); return 0; }


OUTPUT: [10A91A05A3@Linux ~]$ gcc prog9.c [10A91A05A3@Linux ~]$ cat n.c
welcome [10A91A05A3@Linux ~]$ cat j.c aditya college [10A91A05A3@Linux ~]$
./a.out n.c j.c [10A91A05A3@Linux ~]$ cat n.c cat: n.c: No such file or directory
[10A91A05A3@Linux ~]$ cat j.c welcome

				
DOCUMENT INFO
Shared By:
Tags:
Stats:
views:2
posted:9/22/2013
language:
pages:1