/* Program to copy a source file into the target file and display the target file using system calls.
*/
#include<stdio.h>
#include<stdlib.h>
main(int argc, char *argv[3])
{
int fold,fnew;
if(argc!=3)
{
printf("Read two arguments");
exit(1);
}
fold=open(argv[1],0);
if(fold==1)
{
printf("Unable to open file %s\n",argv[1]);
exit(1);
}
fnew=creat(argv[2],0666);
if(fnew==-1)
{
printf("Unable to create file %s\n",argv[2]);
exit(1);
}
copy(fold,fnew);
exit(0);
}
copy(int old,int new)
{
int count;
char buffer[512];
while(read(old,&buffer,1)>0)
{
write(new,&buffer,1);
}
}
OUTPUT SCREEN:
*/
#include<stdio.h>
#include<stdlib.h>
main(int argc, char *argv[3])
{
int fold,fnew;
if(argc!=3)
{
printf("Read two arguments");
exit(1);
}
fold=open(argv[1],0);
if(fold==1)
{
printf("Unable to open file %s\n",argv[1]);
exit(1);
}
fnew=creat(argv[2],0666);
if(fnew==-1)
{
printf("Unable to create file %s\n",argv[2]);
exit(1);
}
copy(fold,fnew);
exit(0);
}
copy(int old,int new)
{
int count;
char buffer[512];
while(read(old,&buffer,1)>0)
{
write(new,&buffer,1);
}
}
OUTPUT SCREEN:
No comments:
Post a Comment