Please bear with me since I'm still really new to C programming. When I run this code:
#include <time.h>
#include <stdio.h>
#include <unistd.h>
int main(void)
{
while (1) {
time_t mytime;
mytime = time(NULL);
printf("%s Hello world\n", ctime(&mytime));
sleep(1);
}
return 0;
}
The output always looks like this:
Wed Jan 18 02:32:32 2017
Hello world
Wed Jan 18 02:32:33 2017
Hello world
Wed Jan 18 02:32:34 2017
Hello world
What I want is like this:
Wed Jan 18 02:32:32 2017 Hello world
Wed Jan 18 02:32:33 2017 Hello world
Wed Jan 18 02:32:34 2017 Hello world
How can I do that ?
Note:
If I remove \n
from printf("%s Hello world\n", ctime(&mytime));
it'll result like this:
Wed Jan 18 02:38:29 2017
Hello worldWed Jan 18 02:38:30 2017
Hello worldWed Jan 18 02:38:31 2017
Hello worldWed Jan 18 02:38:32 2017
Hello worldWed Jan 18 02:38:33 2017