我在以下代码中收到分段错误(核心转储):
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);
}
我的结构如下:
struct logData
{
char *clientName;
char *filename;
char *timestamp;
};
有人可以帮忙吗?