473,386 Members | 1,652 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,386 software developers and data experts.

Convert array to float

Hello, i wrote a client in C, that read value of voltages.
I read, in output, this value like a string, for example:
+3.91 +0.29 +2.27 +1.21 +2.45 +4.48 +3.14 +0.72 +1.12 +4.73 +0.58 +1.87
......
in a for loop.
Inside this for loop, i insert a for clicle to convert the string to float.
[PHP] char *pEnd=buffer;
double v, r, tempeature;
int i;
for (i = 0; i < 12; i++)
{
v = strtod(pEnd, &pEnd);
printf("\n v = %+5.2f\n", v);
}
[/PHP]
The problem is that in ouput i have the wrong value.
Jan 24 '08 #1
3 2445
Please, i need help.
I have a big problem, after the funcion read_from_server, i put the for cicle to comvert the buffer in to float.
pLEASE HELP ME
Jan 25 '08 #2
Savage
1,764 Expert 1GB
Hello, i wrote a client in C, that read value of voltages.
I read, in output, this value like a string, for example:
+3.91 +0.29 +2.27 +1.21 +2.45 +4.48 +3.14 +0.72 +1.12 +4.73 +0.58 +1.87
......
in a for loop.
Inside this for loop, i insert a for clicle to convert the string to float.
[PHP] char *pEnd=buffer;
double v, r, tempeature;
int i;
for (i = 0; i < 12; i++)
{
v = strtod(pEnd, &pEnd);
printf("\n v = %+5.2f\n", v);
}
[/PHP]
The problem is that in ouput i have the wrong value.
This code should do fine.Is this inside of some function(other then main)?
If so have you tried checking the buffer contents to see if it has what you think it should have?
Jan 25 '08 #3
This code, it's inside th function main , only.
The buffer is defined: char buffer[1024].
In output i have 12 value of voltages, where each value are: plus sign, a number,period, number, number and blanck space.
Jan 28 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jinming Xu | last post by:
Hello everyone, While embedding my C++ program with Python, I am impeded by the conversion from a Python Tuple to a C++ array. I hope to get some assistance from you guys. I have a sequence...
2
by: Goran | last post by:
Hi! I need to convert from a unsigned char array to a float. I don't think i get the right results in the program below. unsigned char array1 = { 0xde, 0xc2, 0x44, 0x23}; //I'm not sure in...
15
by: fdunne2 | last post by:
The following C-code implements a simple FIR filter: //realtime filter demo #include <stdio.h> #include <stdlib.h> //function defination float rtFilter1(float *num, float *den, float...
12
by: GRoll35 | last post by:
I get 4 of those errors. in the same spot. I'll show my parent class, child class, and my driver. All that is suppose to happen is the user enters data and it uses parent/child class to display...
4
by: viks | last post by:
Hi guys I need little help here . I want to convert 'System::Object __gc * array ' to 'float array' Lets say I have object Reader with method Send ,it returns a variant that contains a...
7
by: SpreadTooThin | last post by:
I have some code... import array a = array.array('d') f = open('file.raw') a.fromfile(f, 10) now I need to convert them into floats (32 bit...) what do i do?
0
by: jeff_rowa | last post by:
Hi guyz, Could anyone please tell me how can I convert an array of floats to a string? I know that I can use this code to convert one float to a string but what is the best way for an array of...
1
by: =?Utf-8?B?Zmx5ZmlzaGVyMTk1Mg==?= | last post by:
I am reading values from a device through a TCP/IP socket that represent an ANSI float value. However, the values come across as 2 elements in a ushort array. I need to map the 2 values bit...
12
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} ...
33
by: Adam Chapman | last post by:
Hi, Im trying to migrate from programming in Matlab over to C. Im trying to make a simple function to multiply one matrix by the other. I've realised that C can't determine the size of a 2d...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.