This is the part of code I'm working on:
void update_log(char *name, pthread_t ID, char *status, char *update)
{
time(&rawtime);
time_str = asctime(localtime(&rawtime));
time_str[strlen(time_str) - 1] = 0;
fprintf(log_file, "[%s] [%12s] [%u] [%s] %s\n", time_str, name, (unsigned int)ID, status, update);
}
The output is:
[Sat Mar 9 21:36:20 2013] [ main] [197777152] [OK] ******
[Sat Mar 9 21:36:20 2013] [update_table] [172680960] [OK] **********
[Sat Mar 9 21:36:22 2013] [update_table] [172680960] [OK] ******
[Sat Mar 9 21:36:25 2013] [ main] [197777152] [OK] ****************
Is there a way to make the output of the name variable look like this(so it would still take 12 blocks and still would be in brackets):
[Sat Mar 9 21:36:20 2013] [main] [197777152] [OK] ******
[Sat Mar 9 21:36:20 2013] [update_table] [172680960] [OK] **********
[Sat Mar 9 21:36:22 2013] [update_table] [172680960] [OK] ******
[Sat Mar 9 21:36:25 2013] [main] [197777152] [OK] ****************
I was thinking about adding brackets to name variable before fprintf() function, but is there a easy way in C to add a character to the beginning of the string?
Thanks.