fgets Isn't Waiting For Me

Discussion in 'Mac Programming' started by Halfmaster1, Mar 18, 2011.

  1. Halfmaster1 macrumors newbie

    Joined:
    Dec 28, 2010
    #1
    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
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    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
     
  3. Timmo78 macrumors newbie

    Joined:
    Feb 3, 2008
    #3
    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);
     
  4. Halfmaster1, Mar 18, 2011
    Last edited: Mar 18, 2011

    Halfmaster1 thread starter macrumors newbie

    Joined:
    Dec 28, 2010
    #4
    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.
     

Share This Page