NaN said:
Presumably you're using it as a C compiler, not as a C++ compiler.
Here is my sourcecode.
/* GETCH.C: This program reads characters from
* the keyboard until it receives a 'Y' or 'y'.
*/
#include <conio.h>
#include <ctype.h>
void main( void )
{
int ch;
_cputs( "Type 'Y' when finished typing keys: " );
do
{
ch = _getch();
ch = toupper( ch );
} while( ch != 'Y' );
_putch( ch );
_putch( '\r' ); /* Carriage return */
_putch( '\n' ); /* Line feed */
}
Can u help?
Please don't use silly abbreviations like "u". Take the time to type
out the whole word. Don't make reading your message more difficult
than it has to be.
Please put your question in the body of your message. Some
newsreaders don't make it easy to see the subject header while reading
a message. (Your subject was "Reading input doesn't work".)
Can we help with what exactly? You say it "doesn't work". There are
a nearly unlimited number of ways in which something can "not work".
You need to tell us what you expected what you got, and how they
differ; we're not mindreaders.
"void main(void)" needs to be "int main(void)". And since main()
returns an int, you should actually return an int; add "return 0;"
before the closing brace.
The following are non-standard:
<conio.h>
_cputs
_getch
_putch
The standard I/O routines are declared in <stdio.h>. Consult your
textbook for instructions on how to use them. Nothing you're trying
to do here (as far as I can tell) requires anything beyond standard C
features.
Assuming that _putch is intended to print a character to standard
output (or the console, or whatever), you probably don't need the
'\r'. A single '\n' character represents a new-line; it should be
translated as necessary for your system.
You only call _putch for a single character, followed by '\r' and
'\n'. Since the loop won't terminate until ch has the value 'Y', that
single character will inevitably be 'Y'. Without knowing what you're
trying to do, I can't guess whether that's what you want.
Suggested reading:
The comp.lang.c FAQ, at <
http://www.c-faq.com/>.
Eric Raymond's "How To Ask Questions The Smart Way", at
<
http://www.catb.org/~esr/faqs/smart-questions.html>.