modified getchar function