Converting Float to (char*) for Winsock sendv() + recv()

Posted on 2005-05-07
Last Modified: 2008-02-07
As I cannot type cast , Is there any way to do this ? Is there any function I can use to do this ? Is there any alternative network commands I can use to send floats ?

Thanks Mark
Question by:Paladin_VB
    LVL 19

    Accepted Solution

    Cant you just use sprintf ?

    char buffer [50];

    sprintf(buffer, "This is my float value %f", m_float);

    LVL 11

    Expert Comment

    could you not use atof()
    LVL 11

    Expert Comment

    #include <stdlib.h>
     #include <stdio.h>

     int main(void)
        float f;
        char *str = "5432.123";

        f = atof(str);
        printf("string = %s float = %f\n", str, f);
        return 0;
    LVL 1

    Author Comment

    Thanks to to all who replied
    LVL 19

    Expert Comment

    Glad to help.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Article by: SunnyDark
    This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
    What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now