You are on page 1of 2

Operating System-LAB

Submitted by :
AREEB AHMED 17271519-157
MUHAMMAD ALI 17271519-111
HAMAD RAZA 17271519-080
Submitted to:
Ms. Atiqa
--------------------------------------------------------------------------------------------
Department Of Computer Science
Hafiz Hayat Campus
--------------------------------------------------------------------------------------------
#include<stdio.h>

#include<sys/types.h>

#include<sys/stat.h>

#include<unistd.h>

#include<fcntl.h>

void main()

int file1,file2,n;

char desti[30],ch[5];

struct stat s,t,w;

file1=creat("text.txt",0644);

printf("Enter the file to be copied\n");

scanf("%s",desti);

file2=open(desti,O_RDONLY);

if(file2==-1)

perror("file doesnot exist");


exit(0);

while((n=read(file2,ch,1))>0)

write(file1,ch,n);

close(file2);

stat(desti,&s);

printf("Source file size=%d\n",s.st_size);

fstat(file1,&t);

printf("Destination file size =%d\n",t.st_size);

close(file1);

You might also like