CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2001
    Location
    CA
    Posts
    35

    Convert double to string / Send double using UDP

    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!


  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Convert double to string / Send double using UDP

    >> 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

  3. #3
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Convert double to string / Send double using UDP

    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

  4. #4
    Join Date
    Jan 2001
    Location
    CA
    Posts
    35

    What about longlong to string?

    How about converting LONGLONG to string, and coverting string to LONGLONG??

    Thanks!


  5. #5
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: What about longlong to string?

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured