fprintf and ctime without passing \n from ctime
You can use a combination of strftime()
and localtime()
to create a custom formatted string of your timestamp:
char s[1000];
time_t t = time(NULL);
struct tm * p = localtime(&t);
strftime(s, 1000, "%A, %B %d %Y", p);
printf("%s\n", s);
The format string used by ctime
is simply "%c\n"
.
You can use strtok()
to replace \n
with \0
. Here's a minimal working example:
#include <stdio.h>
#include <string.h>
#include <time.h>
int main() {
char *ctime_no_newline;
time_t tm = time(NULL);
ctime_no_newline = strtok(ctime(&tm), "\n");
printf("%s - [following text]\n", ctime_no_newline);
return 0;
}
Output:
Sat Jan 2 11:58:53 2016 - [following text]