I need to print out this: Temperature = "temperature" @ "date/time", where "date/time" is the date and time as returned by the Linux 'date' command.
When I use system("date") in my program it displays it immediately. Is there a way to keep this from happening?
This is my code so far:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#define FREQUENCY 5
#define MIN -10
#define MAX 35
int main()
{
time_t t;
/*
* Initialize random number generator
*/
srand((unsigned) time(&t));
/*
* Print random values between -10 and +35°C
*/
while(1)
{
double random = ((double)rand() * (MAX-MIN))/(double)RAND_MAX+MIN;
printf("Temperature = %1.2f @ %d\n", random, system("date"));
fflush(stdout);
sleep(FREQUENCY);
}
}