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

outputing words in a string and number of times they occur

Hi. i need some help with some homework i was given. i am using windows visual studio to make my program. the program should read in a string of characters then output the the words in that string and how many times it occurs. any help would be appreciated
Dec 6 '06 #1
2 1662
tracey
1
I have a similiar program, it ask you to enter a string, then enter a character, then it displays the number of times the character occurs in the string. I'm using c++ programming.

any help would be useful.
Dec 6 '06 #2
DeMan
1,806 1GB
This question comes up remarkably often, and you should look through the posts before submitting. You should also (in any forum) post any code that can show your progress (you will find people reluctant to do your entire assignment for you).

Basically what I would do is:
1)get a String (and array/stream of character) from the input.
2)sort the string into alphabetical (or any order so long as like characters appear together) order.
3) when the search character is entered, look for it (by iterating the entire length or by other means) in the string and count for how long it occurs .

eg if
Input = "The rain in spain falls mainly in the plain"
sortedString = "aaaaaefhiiiiiillllmnnnnnnpprst"
char=i;
loop characters to find i then count
Expand|Select|Wrap|Line Numbers
  1. while(currentChar==i)
  2. {
  3.   counter++;
  4.   *currentChar++
  5. }
  6.  
This is not necessarily the best (or even easiest answer) but I leave it tou you to either implement, improve on or find something else....
Dec 6 '06 #3

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

Similar topics

4
by: Ken Fine | last post by:
I'm looking to find or create an ASP script that will take a string, examine it for a search term, and if it finds the search term in the string, return the highlighted search term along with the...
27
by: Mike P | last post by:
I will be passing my function a two dimensional array of varying length. Within that array is one data point, and the number of times it should loop through. So, for example, I might pass this...
17
by: Chad Myers | last post by:
I've been perf testing an application of mine and I've noticed that there are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String instances being created. I've done some...
1
by: Dixie | last post by:
I have 4 fields (byte) which can each contain a number between 1 and 40 odd.. The numbers in each of the fields represents the same information that can occur in one of 4 places. In each set of...
7
by: Jay | last post by:
How would I be able to grab random words from an internet source. I'd like to grab a random word from a comprehensive internet dictionary. What would be the best source and the best way to go...
20
by: dmurray14 | last post by:
Hey guys, I'm a C++ newbie here - I've messed with VB, but I mostly stick to web languages, so I find C++ to be very confusing at times. Basically, I am trying to import a text file, but I want...
0
by: Tigerlily | last post by:
Hello! I need to count the number of words in a string read in from an infile, in a function, but I don't know how to do this. This is what I have so far. //Tiffany Lynn Goodseit #include...
6
by: Xernoth | last post by:
Hi, I have an exercise that requests the following: Write a function that reads words from an input stream and stores them in a vector. Use that function both to write programs that count the...
0
by: arnuld | last post by:
any comments for improvement: /* C++ Primer - 4/e * * CHAPTER 10 - Associative Containers * * EXERCISE - 10.7 * Write a program to count and print the number of times each word *...
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...
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.