Hello friends,
Please have a look in the below given C code programmed in Ubuntu Linux:
Even this code is showing me the same error:Code:void Log(char *message) { mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH; int fd; size_t length = strlen(message); if (file_exists(logfile)) fd = open(logfile, O_WRONLY | O_APPEND | O_CREAT, 0666); else fd = open(logfile, O_WRONLY | O_EXCL | O_CREAT, 0666); if(fd == -1) { printf("%s\n", "Log file open/create error."); return; } else fd = write(fd, message, length); }
The above code is giving me error:Code:void Log(char *message) { mode_t mode = 0666; FILE *fd; if (file_exists(logfile)) fd = fopen(logfile, "a"); else fd = fopen(logfile, "w"); if(fd == NULL) { fprintf(stderr, "Log file open/create error."); } else fprintf(fd, "%s", message); fclose(fd); }
Please help.Code:Segmentation fault (core dumped)



LinkBack URL
About LinkBacks


