473,396 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sending Float values...

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....
Dec 9 '07 #1
3 2123

"swetha" <la*******@gmail.comwrote 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

Dec 9 '07 #2
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);
Dec 10 '07 #3
On 12ÔÂ10ÈÕ, ÏÂÎç12ʱ15·Ö, James Fang <fangshang...@gmail.comwrote:
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
an amendment to my above post:
host:snprintf(floatArray,sizeof(floatArray),"%f\r\ n",a);
Dec 10 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Alexander Malkis | last post by:
What is the biggest float number f so that -f doesn't overflow and is still representable as a float. -- Best regards, Alex. PS. To email me, remove "loeschedies" from the email address...
2
by: Shi Jin | last post by:
Hi there, I have been thinking this for quite a while: if we are considering the number of different representations of one type,say int and float, is there any difference as long as they are...
7
by: Johnathan Doe | last post by:
I can google search to find the range of values that can be represented in a float by reading up on the IEEE std, but is that the same as how many distinct values that can go in a float type? ...
16
by: Gerald Lafreniere | last post by:
{ float F=123.456000; F*=1000; // Actually I used a for loop F*=10 three times. printf("%f\n", F); } This will produce something like 123456.00XXXX, where XXXX are garbage digits. Why...
11
by: Marc Pelletier | last post by:
Hello, I am having trouble implementing the following callback: CNCSError CECWCompressor::WriteReadLine(UINT32 nNextLine, void **ppInputArray) where ppInputArray is a 3 by x array. The...
3
by: Juergen | last post by:
hi, I've got a problem sending floating point values to an corba server. With other datatyes like short or string it works fine. So having this idl file : module Example{ interface User{
1
by: joesfer | last post by:
I'm trying to develop a graphical user interface for a renderer i've got written in an unmanaged C++ DLL with C#. During the rendering process, several images are sent to a delegate as float*...
6
by: trevor | last post by:
Incorrect values when using float.Parse(string) I have discovered a problem with float.Parse(string) not getting values exactly correct in some circumstances(CSV file source) but in very similar...
7
by: bleachie | last post by:
Hey, I just need some help, my form seems to not send me all of the 'guestNames' and 'guestEmails' forms. i use this function to add more guestnames and guestemail fields based on the number of...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.