Archived

This topic is now archived and is closed to further replies.

RanBlade

Skipping gets() statement

Recommended Posts

void addmov()
{
	


			cout << "Enter movie title: ";
			gets(item[i].title);
			
			item[i].index = i;
		
			cout << "\nEnter Category: ";
			gets(item[i].category);

	
} 
Everytime the function is called it skips the gets(item.title); and just moves on to the next gets() statement before asking for input. So far I havent been able to get it to not skip it. any suggestions on why its doing that would be great thx. RanBlade "Passion is what drives you to stay up until 4am fixing that bug that hardly anyone would notice...Passion is where great games come from, if you dont live and breathe games you shouldn't be in the games industry." - Dave Pottinger, Ensemble Studios [edited by - ranblade on October 10, 2003 3:18:51 PM]

Share this post


Link to post
Share on other sites
This is because there is already a line feed (CRLF) in the keyboard input buffer. Flush it out by calling a secondary gets() or by looking up the buffer IO functions on MSDN and figuring out how to flush the buffer yourself (its been too long since I used IO stream buffers to remember how its done).

In all honesty, you should not use gets() and cout in the same program. Use cin >> variable; instead.

Share this post


Link to post
Share on other sites
as of right now i know no other way to take a multi word string with cin >> so that is why i was using gets(). Ill look around on MSDN

RanBlade
"Passion is what drives you to stay up until 4am fixing that bug that hardly anyone would notice...Passion is where great games come from, if you dont live and breathe games you shouldn''t be in the games industry." - Dave Pottinger, Ensemble Studios

Share this post


Link to post
Share on other sites
Try a getchar() or getch() after the first gets() I'll look into it now but that sounds familiar (and sorry if it doesn't halp at all!)

hmm

char title[128];
char category[128];
cout << "Enter movie title: ";
gets(title);
//_getch();


cout << "\nEnter Category: ";
gets(category);
cout<< endl<<title << endl <<category<<endl;

[/soure]
Works for me.


[edited by - kordova on October 11, 2003 12:12:42 PM]

Share this post


Link to post
Share on other sites
Oh it skips the first one. You must''ve used a cin before it, right? If so, use a getchar(); to be rid of the endl i think gets eats and stops at or such (searching through console code I''ve seen that repeatdly by myself so that must''ve fixed it for me). Cheers.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
what about the string command?


std::string value = item[i].title;


Just a thought.

Share this post


Link to post
Share on other sites