Skip to main content
gamedev.net
🔒 Locked

String loop?

Started by Gameman17 Nov 28, 2001 at 1:30 PM 4 replies 350+ views
Original Post
Gameman17
Gameman17
Well I don''t want put the entire program on here so I have made an example of the problem. //Input/////////////////// #include void input(); void main() { for(int j=0; j<11; j++) { input(); }; } void input() { char name[50]; cout<<"What do you want to do :"; cin.get(name, 49); cout<
Gameman17
Gameman17
When I run this code it asks the question, gets the input, and loops, but when it loops you can no longer input anything it just keeps looping! it''s kind of hard to explain. Enter the code see what mean.
BASSOFeeSH
BASSOFeeSH
Can you use the code tags please. They look like

[ code ] code goes here [ / code ]

Except without the spaces between the brakets.

Wait, wait, wait....who''s Nambla Fett?
-- What would Sweetness do?
krez
krez
quote:
Original post by Gameman17
When I run this code it asks the question, gets the input, and loops, but when it loops you can no longer input anything it just keeps looping! it''s kind of hard to explain. Enter the code see what mean.

this is based on what i have read here on gamedev.net, and i haven''t actually ever experienced this problem, but:
i believe that cin.get() stops when it reaches a space or a carriage return... so if your input is "go north" it will only get "go", and the rest of the input(" north") will stay in the buffer. so, each time after that you call it, it just hits the space again. i think.
use cin.getline() to get everything you type before you hit the "enter" key.

--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.