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

how to take integers out of a scrambled text?

1
so I have this c++ homework which wants me to take a text input like "north6east7west8"(the string follows the "direction+integer order) and have an input check. if the text does not have any integers it ought to give a warning message.

and in another function I should take the integers out of the text (which I have no idea how to do) and convert them with atoi (which I could do).

I hope I explained it clearly. Thanks in advance.
Jul 29 '10 #1
3 1305
@trea
So what exactly is your question?

Also, please see the FAQ about asking for homework solutions.
Jul 29 '10 #2
weaknessforcats
9,208 Expert Mod 8TB
Consider using the >> operator.

Expand|Select|Wrap|Line Numbers
  1. cin >> data;
and data is a char, you have fetched one character. If data is not a char, then the >> operator fails.

So you might try:

Expand|Select|Wrap|Line Numbers
  1. cin >> anInt;
  2.  
  3. If this fails then the data is not an integer, try again using a char
  4.  
  5. cin >> aChar;
Wrap this in a loop an off you go.


Note that an input of 1234x and you perform cin>>anInt will place the value 1234 in anInt. That is, you do not use atoi or atoanythingelse in C++.
Jul 30 '10 #3
whodgson
542 512MB
Another way maybe to get the length of the string 's' with s.length()run through your string within a for loop,using < s.length() as the end condition, and identify the integers with something like if(s[i] >= '0' && s[i]<='9') and increment count++ so that you can print out the number of integers. Can you guarantee there will be only one character in each integer? If not you will need to check if s[i-1] is or is not also an integer.
Alternatively if s[i] is >='a' && <='z' you could could replace 'a' --> 'z' with " " which would leave only the integers.
Aug 1 '10 #4

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

Similar topics

4
by: grghoward | last post by:
I am receiving a series of Microsoft Word documents from web clients that they upload to my server. I need to convert them to XML to pass through to another system. I have done this through...
15
by: rodchar | last post by:
hey all what's the best way to take comma-delimited text file and insert it into a database via oledb provider thanks in advance rodchar
4
by: Dean A. Hoover | last post by:
Is there an example somewhere of a function that will take 2 parameters: text and a text object (input type=text or textarea) and insert that text using the current selection point(s) for the...
2
by: Giovane Calabrese | last post by:
( aspx + vb ) hi everyone ! I really need make that function work ! im brazilian , and i want to make a multilanguage system , that function above must look at all ASPX take the labels ID and...
0
by: Giovane Calabrese | last post by:
ok. im try to make a multilanguage system based on that tutorial : http://www.123aspx.com/redir.aspx?res=29112 in my aspx pages all text are in labels , and i want to take the name labels...
8
by: AFN | last post by:
I want to have a routine in a page base class that will take all the text fields on a web form, and then HtmlEncode their values. I'm having trouble figuring out if I want to loop controls or...
0
by: Darin | last post by:
I have a comma-delimited text file that I am reading via a connection string: junk = "Provider=Microsoft.Jet.OLEDB.4.0;" junk &= "Data Source=\inware\data\df;" junk &= "Extended...
7
by: Malcolm | last post by:
This is a program to convert a text file to a C string. It is offered as a service to the comp.lang.c community. Originally I thought it would be a five minute job to program. In fact there are...
3
by: michael sorens | last post by:
The documentation for the RichTextBox is sketchy at best. I want to do a very simple task but I cannot find information on this. I am using a RichTextBox as an output window. Some text I want to...
5
by: Ben | last post by:
Hi, I am looking to incorporate the scrambled text functionality (a graphic etc with scrambled text appears and the user is required to type in what he sees to prevent anonymous hits/spamming etc....
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: 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
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
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.