Thread: while loop char input

  1. #1
    Musicman - Canora
    Join Date
    Aug 2005

    while loop char input

    Hey guys is there anything wrong with how im getting the input for a single character because for some reason the if statement is not working properly.

    Even if i do enter the correct input it still prints as invalid?

    char guessType()
      char type;
      int valid;
      printf("Enter guess type((f)lag, (u)ncover or(s)weep:\n");
      valid = 0;
      while((type = fgetc(stdin) != '\n' && type != EOF))
           if(type != 's' || type !='u' || type != 'f')

  2. #2
    Registered User wintellect's Avatar
    Join Date
    Mar 2006
    Your if() statement should test as follows:
    if(type != 's' && type !='u' && type != 'f')
    Last edited by wintellect; 04-09-2006 at 01:33 PM.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    >char type;
    >type = fgetc(stdin)
    fgetc() doesn't return a char, it returns an int.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 01:20 PM
  2. Can't get loop to work or validation
    By eminem3150 in forum C++ Programming
    Replies: 11
    Last Post: 01-15-2008, 05:21 AM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  5. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 12:18 AM