Sending Float values...

S

swetha

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

Malcolm McLean

swetha said:
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.
 
J

James Fang

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);
 
J

James Fang

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:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top