I am getting Segmentation error(core dump) in the following code:
void Update_Log( )
{
struct logData update;
int file;
char *writeBuffer=NULL;
if((file=creat("/home/user/Desktop/DMS/DMS/filename.txt",O_RDONLY|O_WRONLY))==-1)
perror("file not opened");
update.clientName="user";
update.filename="user";
update.timestamp="some time";
sprintf(writeBuffer,"%s %s %s",update.clientName,update.filename,update.timestamp);
if((write(file,writeBuffer,sizeof(writeBuffer)))==-1)
perror("write unsuccessful");
close(file);
}
My structure is as follows:
struct logData
{
char *clientName;
char *filename;
char *timestamp;
};
Can anyone help in this?