fgets Isn't Waiting For Me

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

  1. Halfmaster1 macrumors newbie

    Dec 28, 2010
    I am using the fgets

    char extraString[20];
    		while (i!=20) 
    		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.

  2. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
    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?

  3. Timmo78 macrumors newbie

    Feb 3, 2008
    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.

    memset (extraString, 0, 20);
  4. Halfmaster1, Mar 18, 2011
    Last edited: Mar 18, 2011

    Halfmaster1 thread starter macrumors newbie

    Dec 28, 2010
    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