Click to See Complete Forum and Search --> : Convert double to string / Send double using UDP
Cloudthegreat
February 24th, 2002, 12:17 AM
Hi! Is there a library function that lets me easily convert a double into a char* string?
Or, if what I really want to do is to send a double using UDP using its sendto() funciton, how can I send and receive the double?
Thanks a lot!
Andreas Masur
February 24th, 2002, 12:42 AM
>> Hi! Is there a library function that lets me easily convert a double into a char* string?
double dftValue = 3.1774;
char szString[25] = "";
sprintf(szString, "%.6lf", dftValue);
>> Or, if what I really want to do is to send a double using UDP using its sendto() funciton, how can >> I send and receive the double?
double dftValue = 3.1453;
sendto(Socket, reinterpret_cast<const char *>(dftValue), sizeof(dftValue), 0, NULL, 0);
Ciao, Andreas
"Software is like sex, it's better when it's free." - Linus Torvalds
Andreas Masur
February 24th, 2002, 12:43 AM
It should be
sendto(Socket, reinterpret_cast<const char *>(&dftValue), sizeof(dftValue), 0, NULL, 0);
in my previous post....
Ciao, Andreas
"Software is like sex, it's better when it's free." - Linus Torvalds
Cloudthegreat
February 24th, 2002, 01:42 AM
How about converting LONGLONG to string, and coverting string to LONGLONG??
Thanks!
Andreas Masur
February 24th, 2002, 09:42 AM
1. LONGLONG to string
#include <stdlib.h>
char szBuffer[50] = "";
LONGLONG llLongLong = 5365462;
_i64toa(llLongLong, szBuffer, 10);
2. String to LONGLONG
#include <stdlib.h>
char szBuffer[] = "376329987";
LONGLONG llLongLong = _atoi64(szBuffer);
Ciao, Andreas
"Software is like sex, it's better when it's free." - Linus Torvalds
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.