# getchar() in C on Unix



## Underclocker (Aug 13, 2007)

Hi, I'm trying to write a portion of a program that outputs error when characters other than A, B and S are inputted with the use of getchar() then end, except I can't get it to work. Currently it looks like this:


```
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main( void ) {

  int ch;

  printf( "Input characters:\n" );
  
  while ( ch != '\n' ) {

    ch = getchar();
    if( ch != 'A' || ch != 'B' || ch != 'S' ) {

      printf( "\nError: Please only input A, B and S.\n" );
      return 0;
      
    }

  }

return 0;

}
```
Can someone please tell me what I'm doing wrong?


----------



## Underclocker (Aug 13, 2007)

Nevermind, I figured out what's wrong...


----------

