Truncation operation not performed
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
int main(){
int d,i;
char buf[50];
bzero(buf,50);
for(i=0;i<3;i++){
read(0,buf,50);
d = open("h.c",O_RDWR|O_TRUNC);
if(d<0){
printf("error");
exit(0);
}
printf("%d\n",d);
write(d,buf,50);
write(1,buf,50);
close(d);
}
}
in this program why the truncated operation is not performing on file
|