Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Halfmaster1

macrumors newbie
Original poster
Dec 28, 2010
19
0
I am using the fgets

Code:
char extraString[20];
		
		i=0;
		while (i!=20) 
		{
			extraString[i]=0;
			i++;
		}
		i=0;
		
		fgets(extraString, 20, stdin);

Bu the program skips right over it, going on the the rest of the code, even thought I haven't typed a single letter.

Thanks
 
Can you post a full compilable example?

Can you show us what's stored in extraString?

Does this happen the very first time you try fgets, or only subsequent attempts?

-Lee
 
What is the return code from fgets? How is the application being launched?
eg: If you're launching it on a console, then STDIN should be a valid input stream. Some other launch mechanism may not have a valid input stream, and thus result in EOF for any call against STDIN.


Also.. you might want to look at memset to clear your extraString variable.

Code:
memset (extraString, 0, 20);
 
Sorry for taking so long, I had things to do.

That is an exact copy paste from my code. I later add the values of the chars, and use that number elsewhere in the program, to allow the user to control the outcome, with a word, that is easier to remember.

Oh, and thanks for the memset function, I'll use it in the future.

Thanks. (<--should make that my signature)


Edit: It started working again. Don't know why, I didn't change anything.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.