473,669 Members | 2,452 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Seperate numbers from String as double

6 New Member
HI All;

I am writing a software for a machine and it is working.But the out put comes as a string in this format:

Expand|Select|Wrap|Line Numbers
  1. READOUT "  -0.01 V,  -0.04 A"  /n
Is it possible to get the two values i.e -0.01 and 0.04 into two double variables?This is necessary as this has to be exported to a function in this format.

Thanks in advance and regards
Jun 18 '07 #1
5 1798
Savage
1,764 Recognized Expert Top Contributor
HI All;

I am writing a software for a machine and it is working.But the out put comes as a string in this format:

Expand|Select|Wrap|Line Numbers
  1. READOUT "  -0.01 V,  -0.04 A"  /n
Is it possible to get the two values i.e -0.01 and 0.04 into two double variables?This is necessary as this has to be exported to a function in this format.

Thanks in advance and regards
By output do you mean output to the file or output to the screen.If it is to the file check article in article section:

How to parse a line?

Savage
Jun 18 '07 #2
RAMBO29
6 New Member
Hi Savage;
Its is to be posted to a file.But its by a dedicated function.So if its possible to have the values in 2 variables lets say a=0.04 and b=0.01 it will be okay.

Thnx and regards
Jun 18 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
READOUT " -0.01 V, -0.04 A" /n
Use a stringstream. Insert our string into the stream an extract into separate variables.
Expand|Select|Wrap|Line Numbers
  1. void YourFunction(char* yourstring)
  2. {
  3. stringstream ss;
  4. ss << yourstring;
  5. char str[20];
  6. char ch;
  7. double d1;
  8. double d2;
  9. //READOUT  "   -0.01       V        ,  -0.04        A       "  /n
  10.           V        V       V       V       V       V        V       V
  11. ss >> str >> ch >> d1 >> ch >> ch >> d2 >> ch >> ch;
  12. ss.ignore();  //eat the \n
  13. {
  14.  
Jun 18 '07 #4
Savage
1,764 Recognized Expert Top Contributor
Hi Savage;
Its is to be posted to a file.But its by a dedicated function.So if its possible to have the values in 2 variables lets say a=0.04 and b=0.01 it will be okay.

Thnx and regards
If you are using c++ you can use formatedd output overloaded operator >>,but if you are using c you will need to read as unformated data and then convert to double using atof.

Savage
Jun 18 '07 #5
RAMBO29
6 New Member
Hi Savage;
Thanks for the info.I am using C.So I will try to use the atof().

Expand|Select|Wrap|Line Numbers
  1. ss >> str >> ch >> d1 >> ch >> ch >> d2 >> ch >> ch;
Does this line try to extract all the individual parts?

Regards
Jun 19 '07 #6

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

Similar topics

2
1438
by: Jesse | last post by:
I'm trying to read numbers from a string with the format '(1,2,3,4,5)'. Each number needs to go into the array, number. If the input string is not formatted as above, an error message will be outputted. The numbers do not have to be of type int(can be fractions) I know I need to separate the string into smaller substrings then convert the substrings to type double to be placed into the array but I'm stuck at what to do first. Can anyone...
4
2012
by: JeffM | last post by:
Quick C# question: I have comma delimited values in a string array that I want to pass to seperate variables. Any tips on splitting the array? Thanks in advance! JM
8
1847
by: microsoft.news.com | last post by:
I have a text file that has a column of numbers that i need to add to get a total of. Is there any way to add the number column in my text file? the text file looks like this: BMW 25,252.00 1/1/2005 BMW 19,000.00 3/15/2005 I need to add the money colum to get 44,252.00. is that even possible from a
5
4073
by: soeren | last post by:
Hello, two days ago I stumbled across a very strange problem that came up when we were printing tiny double numbers as strings and trying to read them on another place. This is part of an object serialisation framework that cannot be done in binary format currently, so please no comments about this ,-)) It took quite some time to shrink down the problem but it looks like that C++ does not behave well in regards to very tiny numbers.
5
2115
by: RAMBO29 | last post by:
Hi I am a bit new to this field and came across a small problem.I tried to find the solution for almost 2 days and havent been able to.I hope some one there can help.I am sure its a small things but just cant get it right. Well I have some things like s=12,56,3,4 \\s is a string I have to take out the values i.e 12,56,3 and 4 and convert to integer values.The limit is the comma.I tried to use something to find how many numbers are...
0
1710
by: heplesser | last post by:
Summary: Does the C++ standard require std::basic_istream<>::operator>>(double&) to leave the input stream untouched in case of a read failure? Details: I noticed an unexpected behavior of operator>>() for numbers (double, int) when reading from cin. I would like to ask for expert clarification on whether I am misunderstanding the rules of the game, or whether my library implementation has a bug. I tested this on g++
3
1379
by: d.avitabile | last post by:
I have a C++ code that is reading a list of parameters from a file. PARAMETERS stringParam="stringValue", intParam=4, doubleParam = 3.533, ... END The values can be strings as well as integers or doubles, and I don't know what they will be ( I don't know how the parameter list will look like) . At the moment I have a mechanism that select all the values and read them into C++ strings, regardless of their type.
4
3955
by: marathoner | last post by:
After reading the string representation of a double precision number, -0.417597000000000D+06, from a text file, I am unable to convert it to a double precision number. Here is the code I am using: string result = block.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries); double temp1 = double.Parse(result); After the last statement, I get an unhandled exception.
9
2512
by: Nico VanHaaster | last post by:
Hello, I don't really want to get too much of a debate here, but I have a feeling this just might cause one. I have been trying to increase the performance of one of my applications. (C# .Net web app). Here's the scenario. I fill a dataAdapter with up to 64 columns (but as low as 10) of data, with +-300 rows. 63 of the 64 columns are all numbers, doubles, &
0
8465
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8383
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8895
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7407
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6210
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4386
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2797
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.