Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Sending Float values...

Reply
Thread Tools

Sending Float values...

 
 
swetha
Guest
Posts: n/a
 
      12-09-2007
Hi,
I worte a RPC program for client and server, After computing
(which i already did)..i get a float value.Now i want this value to be
sent to the client .I know how to do with integer (By passing the
addreess using the pointers,but when i am doing the same here iam
getting errors.Can any 1 tell how to do that please.....
for example say i have the value in result variable ;which is
float....now how should i declare and send this to the client side....
 
Reply With Quote
 
 
 
 
Malcolm McLean
Guest
Posts: n/a
 
      12-09-2007

"swetha" <(E-Mail Removed)> wrote in message
> I worte a RPC program for client and server, After computing
> (which i already did)..i get a float value.Now i want this value to be
> sent to the client .I know how to do with integer (By passing the
> addreess using the pointers,but when i am doing the same here iam
> getting errors.Can any 1 tell how to do that please.....
> for example say i have the value in result variable ;which is
> float....now how should i declare and send this to the client side....
>

You need to convert the floats to a common binary format.

If you read the maths section in my book Basic Algorithms (chapter avialable
free, on my website) you will see floating point representation explained.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

 
Reply With Quote
 
 
 
 
James Fang
Guest
Posts: n/a
 
      12-10-2007
On 12月9日, 下午1时41分, swetha <(E-Mail Removed)> wrote:
> Hi,
> I worte a RPC program for client and server, After computing
> (which i already did)..i get a float value.Now i want this value to be
> sent to the client .I know how to do with integer (By passing the
> addreess using the pointers,but when i am doing the same here iam
> getting errors.Can any 1 tell how to do that please.....
> for example say i have the value in result variable ;which is
> float....now how should i declare and send this to the client side....


try to use asc string instead of the float representation in memory:

#define MAX_FLOAT_LEN 32

int main() {
float a = 1.1;
char floatArray[MAX_FLOAT_LEN];
memset(floatArray,0,sizeof(floatArray));
snprintf(floatArray,sizeof(floatArray),"%f",a);
printf("%s\n",floatArray);
}

you can call send(fd, floatArray, strlen(floatArray),0); to send the
char array to the remote peer.
If you are using TCP as the transport layer protocol, it's better to
add "\r\n" in the end of the float string, so that you can distinguish
the float string from the remote
host:snprintf(floatArray,sizeof(floatArray),"%fr\n ",a);
 
Reply With Quote
 
James Fang
Guest
Posts: n/a
 
      12-10-2007
On 12月10日, 下午12时15分, James Fang <(E-Mail Removed)> wrote:
> On 12月9日, 下午1时41分, swetha <(E-Mail Removed)> wrote:
>
> > Hi,
> > I worte a RPC program for client and server, After computing
> > (which i already did)..i get a float value.Now i want this value to be
> > sent to the client .I know how to do with integer (By passing the
> > addreess using the pointers,but when i am doing the same here iam
> > getting errors.Can any 1 tell how to do that please.....
> > for example say i have the value in result variable ;which is
> > float....now how should i declare and send this to the client side....

>
> try to use asc string instead of the float representation in memory:
>
> #define MAX_FLOAT_LEN 32
>
> int main() {
> float a = 1.1;
> char floatArray[MAX_FLOAT_LEN];
> memset(floatArray,0,sizeof(floatArray));
> snprintf(floatArray,sizeof(floatArray),"%f",a);
> printf("%s\n",floatArray);
>
> }
>
> you can call send(fd, floatArray, strlen(floatArray),0); to send the
> char array to the remote peer.
> If you are using TCP as the transport layer protocol, it's better to
> add "\r\n" in the end of the float string, so that you can distinguish
> the float string from the remote


an amendment to my above post:

> host:snprintf(floatArray,sizeof(floatArray),"%f\r\ n",a);


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
float to string to float, with first float == second float Carsten Fuchs C++ 45 10-08-2009 09:47 AM
operator== (float, float) Jukka Lehtonen C++ 5 08-05-2004 08:28 AM
need code to convert float format to internal java float format which is kept in 4 bytes integer Andy Java 7 05-10-2004 09:26 PM
static_cast<float>(a) versus float(a) Jim West C++ 4 01-16-2004 12:36 PM
Re: float->byte->float is same with original float image. why float->ubyte->float is different??? bd C Programming 0 07-07-2003 12:09 AM



Advertisments