Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,943 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,411 people online right now. Registration is fast and FREE... Join Now!




using method gets()

 
Reply to this topicStart new topic

using method gets()

shammur
19 Jan, 2008 - 10:37 AM
Post #1

New D.I.C Head
*

Joined: 10 Oct, 2007
Posts: 5


My Contributions
hi,
i am doing an assignment where i need to run a loop which will stop when i will only press enter; means no input will be give. my prog counts no of words inputed. Now my problem is when i just press enter it counts "0" words and again ask for input, but i want it to stop right there.
to solve this i use // while(gets(s)>0); it runs perfectly but i was told not to use this code(ie. >0) but instead of it use something like:

while(gets(s)){
//counts no of word
// print it
}
can any one plz help me!

User is offlineProfile CardPM
+Quote Post

Tom9729
RE: Using Method Gets()
19 Jan, 2008 - 12:08 PM
Post #2

Debian guru
Group Icon

Joined: 30 Dec, 2007
Posts: 1,590



Thanked: 12 times
Dream Kudos: 325
My Contributions
Please post your code. code.gif
User is online!Profile CardPM
+Quote Post

cricketfancy
RE: Using Method Gets()
20 Jan, 2008 - 02:54 AM
Post #3

New D.I.C Head
*

Joined: 12 Jan, 2008
Posts: 15


My Contributions
QUOTE(shammur @ 19 Jan, 2008 - 11:37 AM) *

hi,
i am doing an assignment where i need to run a loop which will stop when i will only press enter; means no input will be give. my prog counts no of words inputed. Now my problem is when i just press enter it counts "0" words and again ask for input, but i want it to stop right there.
to solve this i use // while(gets(s)>0); it runs perfectly but i was told not to use this code(ie. >0) but instead of it use something like:

while(gets(s)){
//counts no of word
// print it
}
can any one plz help me!

be more specific
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 04:52PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month