Hi,
How can I erase the data stored in /tmp/a.txt after every run of this code?
Code:
#include <stdio.h> // IO operations
#include <unistd.h> //for pid, ppid, fork functions
#include <sys/types.h> //for pid_t type, kill function
#include <stdlib.h> //for exit function
#include <signal.h> //for kill function
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include <error.h>
int main()
{
int fd;
pid_t x=fork();
char bufferSize[80];
char buffer[]="Wellcome to Linux Embedded";
char bufferNull[]=" ";
fd=open("/tmp/a.txt", O_RDWR | O_CREAT ,0777);
//printf("fd=%d\n",fd);
if(fd==-1)
{
printf("can't open file\n");
}
if(x>0)
{
read (fd, bufferSize, sizeof(bufferSize));
printf("reading to file\n");
write (fd, buffer, strlen(buffer));
printf("writing to file\n");
}
close (fd) ;// Close the file descriptor
return 0;
}