Char array and Getline question - really basic

Thread Solved
Reply

Join Date: Apr 2008
Posts: 185
Reputation: DemonGal711 is an unknown quantity at this point 
Solved Threads: 10
DemonGal711 DemonGal711 is offline Offline
Junior Poster

Char array and Getline question - really basic

 
0
  #1
Dec 2nd, 2008
I have to make a program that reads in words, deletes certain ones, stores ones that pass, and then count the total. He didn't exactly specify how the words would be coming it, but I'm assuming that if a space at the end of the word is bad, that it's probably a word on each line. So, getline sounds like the best way to get the information.

Of course, these words he is giving us to store could be a web address for all we know. So, what would be a good size for me to initialize the array to, or is there a way to store it in a string so I wouldn't have to worry about the size.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 670
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: Char array and Getline question - really basic

 
0
  #2
Dec 2nd, 2008
  1. string myString;
  2. getline(cin, myString);

Chris
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,670
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 192
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: Char array and Getline question - really basic

 
0
  #3
Dec 2nd, 2008
It kind of depends on how the assignment defines "words". If you mean any sequence of displayable characters, bounded by whitespace (thus, a punctuation would be included with the word it precedes or follows), then cin >> would do the job of isolating individual words. If you have a more restrictive definition, such as just the sequence of alphabetic characters (no digits or punctuation) you will have to do a bit more more. You could still use the cin >>, then examine the beginning and ending character(s) of the word to determine more about its state. You might trim off punctuation.

cin >> has the benefit of not being concerned with number of words on an input line, it stops at each.

You could use a char array of any large size you want (256, 1024....) or you could use the string type.
"We Americans got so tired of being thought of as dumb by the rest of the world that we went to the polls last November and removed all doubt."
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 185
Reputation: DemonGal711 is an unknown quantity at this point 
Solved Threads: 10
DemonGal711 DemonGal711 is offline Offline
Junior Poster

Re: Char array and Getline question - really basic

 
0
  #4
Dec 2nd, 2008
Thanks. I forgot after that you can have it just output to a string...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC