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

Seperate numbers from String as double

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 1782
Savage
1,764 Expert 1GB
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
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 Expert Mod 8TB
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 Expert 1GB
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
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
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...
4
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
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 ...
5
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...
5
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...
0
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...
3
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...
4
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:...
9
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.