C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-21-2003, 03:21 PM   #1
Registered User
 
Join Date: Sep 2003
Posts: 2
Unhappy need help with cin.get, or cin.ignore

I need help with a class project, I need it to be functions and I really don't understand how to use cin.ignore and cin.get with an input file, but here goes the program is going to process a text file, I pretty much understand that part, and output the data as is so that is easy. The part that I am having trouble with is how to process blanks or white spaces so the the output file will count the number of words on a line the number of lines and the number of paragraphs. I understand the it should read the characters and skip them if they are not blanks so that it can count the words. The extraction operator >> skips blanks so I know that I need to use cin.ignore I would think so that when it comes to a character it will ignore it and read only the blanks so that it can count the words, but how would it count the lines and paragraphs? I also know that I need a counter. so can someone give me some guidence on how to use cin.ignore so it can ignore lines with charaters on it to count the number of lines in a paragraph??? thanks in advance
yoyo is offline   Reply With Quote
Old 09-21-2003, 03:38 PM   #2
unleashed
 
alphaoide's Avatar
 
Join Date: Sep 2003
Posts: 693
Just to give you some hints.
It's a newline after you encounter '\n'
and if the text is like this...

xxxxxxxxxxxxx xxxxxxxxxxx xxx xxxxx xx
xxxxx xxxxxxxxxx xxxxxxxx xxxxxx
----->xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxx xxxxxxxxx xxxxxxx
xxxxxxx

then a a paragraph is when you encounter " " after '\n'
That's one way, the easiest that I could think of for newbee
alphaoide is offline   Reply With Quote
Old 09-21-2003, 03:49 PM   #3
Pursuing knowledge
 
confuted's Avatar
 
Join Date: Jun 2002
Posts: 1,916
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
There are several things in "How do I...level 2" that might be of help
__________________
Away.
confuted is offline   Reply With Quote
Old 09-21-2003, 04:40 PM   #4
Registered User
 
Join Date: Sep 2003
Posts: 2
Quote:
Originally posted by alphaoide
Just to give you some hints.
It's a newline after you encounter '\n'
and if the text is like this...

xxxxxxxxxxxxx xxxxxxxxxxx xxx xxxxx xx
xxxxx xxxxxxxxxx xxxxxxxx xxxxxx
----->xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxx xxxxxxxxx xxxxxxx
xxxxxxx

then a a paragraph is when you encounter " " after '\n'
That's one way, the easiest that I could think of for newbee
yoyo is offline   Reply With Quote
Old 09-22-2003, 09:48 AM   #5
Registered User
 
Join Date: Mar 2002
Posts: 1,595
>> ignores leading white space but doesn't ignore terminating whitespace. Any whitespace char (space, tab, carraige return, newline char, etc) will terminate input. Therefore, if you just use >> you will not be able to tell what caused termination. Since >> leaves the terminating char in the input buffer, you can figure it out, but.....then you might as well read char by char in the first place. That way you can look at the next char once you find a target char. Target char may be spaces (there are routinely two spaces after the last word of a sentence and before the first word of the next sentence) or new line char(if the next char after the new line char is a space followed by a new line char or a new line char itself, then you have (probably) found a new paragraph and not a new line.
elad is offline   Reply With Quote
Old 09-23-2003, 01:14 AM   #6
Grammar Police
 
HybridM's Avatar
 
Join Date: Jan 2003
Posts: 355
Hi yoyo,

Your algorithm will be useless if you type the file, you don't use any full stops or paragraphs! :P
__________________
Thor's self help tip:
Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

OS: Windows XP
Compiler: MSVC
HybridM is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
cin.ignore and cin.get in C Trafalgar Law C Programming 5 11-24-2008 10:34 AM
cin.get and cin.ignore Trafalgar Law C++ Programming 1 09-24-2008 09:49 AM
cin.get(); doesn't work even with cin.ignore(); calumn C++ Programming 34 05-14-2006 11:12 AM
cin.ignore() & cin.get() dragonlady C++ Programming 11 08-08-2005 11:38 PM
Confused about cin.get(); and classes. RaccoonKing C++ Programming 6 07-17-2005 11:44 AM


All times are GMT -6. The time now is 09:22 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22