Re: Convert time_t to char?
Jonathan wrote:
I have taken up C++ programming again and need to write a socket
client, so far I am able to create the connection to the socket.
As I need a unix timestamp in char to put on a socket in a HTTP 1.1
GET request I am looking for a way to convert the unix timestamp to a
char?
Why the question mark? Are you asking us whether you're looking?
Besides, doesn't your server dictate how to do the conversion?
I am using the following code to generate my unix timestamp:
...
time_t mytime; /* calendar time */
mytime=time(NULL); /* get current cal time */
char chTime[10];
// Here I would like to do some conversion
strcpy (buffer, "GET /?t=" . chTime .
"HTTP/1.1\r\nHost: localhost\r\n\r\n");
write(clientSocket, buffer, sizeof(buffer) -1);
...
Any help is appreciated.
What do you expect, really? We have no idea what your server
needs you to do. The syntax with dots is not an acceptable way,
of course, but you probably know that already. Try 'sprintf'
instead:
sprintf(buffer, "GET /?t=" <some kind of format here>
" HTTP/1.1\r\nHost: localhost\r\n\r\n", mytime);
The format could be %d for all I know, but that's something you
need to find out from the documentation for your server.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask