I want to write the PID to a specific file. It echoes the pid in terminal so far. But how to write this PID to a file?
int main()
{
pid_t pid = getpid();
printf("%lu\n", pid);
char *filename = "/.wirebot/pid.txt";
char *home_dir = getenv("HOME");
char *filepath = malloc(strlen(home_dir) + strlen(filename) + 1);
strncpy(filepath, home_dir, strlen(home_dir) + 1);
strncat(filepath, filename, strlen(filename) + 1);
FILE *fp;
fp = fopen(filepath, "w");
if (fp == NULL) {
} else {
fputs("%lu\n", pid, fp);
fclose(fp);
}
}
Too many arguments at fputs is the error I get.