On 12ÔÂ9ÈÕ, ÏÂÎç1ʱ41·Ö, swetha <laptop...@gmail.comwrote:
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);