473,386 Members | 1,785 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.

Some string confusions

Hi, I'm new here and relatively new to c++ as well. I'm trying to write a function which will solve a quadratic equation. The progran needs to distinguish which coefficient is a, b and c. The quadratic is on the command line at argv[2].

So I decided to split the string (quadratic) up to the x

e.g. 4x^2 + 3x + 5

I want the code to read up to x^2 and place the value into a vector. It will then ignore everything until the +/- and then read the value until the x and place that into a vector; once again ignore everything until it passes the +/- and then read the c constant and place that into a vector.
I would prefer to use an array to store the a, b and c values. Can anyone help me with a code to run through the string and extract the required values?


Another issue is this:
Provided i can use an array, can i initialize the array as follows:
arr[0] = a
arr[1] = b
arr[2] = c
where a, b and c can take any values as specified by the user?

Any help would be greatly appreciated.
Oct 30 '07 #1
2 1187
Laharl
849 Expert 512MB
Vectors would be a mistake, because if a is a multidigit number, the code to transfer from the vector to an integer is more complex than to transfer from a string to an integer.

You can use the strtok() C-string function to split up the input string. The code for this is kind of complicated, but there are good sites (cplusplus.com is the one I usually use) that explain it pretty well with examples.
Oct 30 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
You could make a copy of the string and start a loop looking at copy[0]. Maje a decision on what it is and what to do with then erase copy[0]. The rest of the string will slide to the left so on the next cycle of your loop copy[0] will be the 2nd character of the origingal string. The loop continues until you have erases the entire copy.

You might look up finite-state automaton, which is the mechanism used for this sort of thing.

Yes, you can use an array to hold your coefficients. Just be aware that the type of the coefficients must match the element type of the array.
Oct 30 '07 #3

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

Similar topics

15
by: Torsten Mohr | last post by:
Hi, i'd like to pass a reference or a pointer to an object to a function. The function should then change the object and the changes should be visible in the calling function. In perl this...
3
by: Mike | last post by:
Hey guys I am pulling my hair out on this problem!!!!! Any help or ideas or comments on how to make this work I would be grateful! I have been working on this for the past 4 days and nothing I do...
193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
9
by: Worker | last post by:
Hi , i`ve been wondering how many days do you guys need to read an average asp.net programming book, answer honestly please, for example 800 pages big, how many pages a day? I just wanna see if i...
35
by: Justin Weinberg | last post by:
My thoughts on this.... http://msdn.microsoft.com/vbasic/Future/default.aspx?pull=/library/en-us/dnvs05/html/vb9overview.asp My thoughts: 1. Regarding Implicit types, I don't use type...
23
by: Xah Lee | last post by:
The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations Xah Lee, 2006-03-15 Let me summarize: The LISP notation, is a functional notation, and is not a...
30
by: Xah Lee | last post by:
The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations Xah Lee, 2006-03-15 In LISP languages, they use a notation like “(+ 1 2)” to mean “1+2”....
1
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, what's the best way to turn my csv string into sql parms? the sql parms can vary in count. thanks, rodchar
0
by: sonuindia88 | last post by:
I am preparing c for entrance examinations..I am reading Ritchie and Deitel and practising questions from Yashwant Kanetkar...Here are some of the confusions i am having..your help is required.... ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.