Reading input doesn't work

Discussion in 'C Programming' started by NaN, May 1, 2008.

  1. NaN

    NaN Guest

    Hi I'm using Dev-C++.

    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?
    NaN, May 1, 2008
    #1
    1. Advertising

  2. NaN

    Default User Guest

    NaN wrote:

    > Hi I'm using Dev-C++.
    >
    > 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?


    You have a bunch of non-standard, proprietary stuff here. You'll need a
    Dev C++ forum of some sort. If I read it correctly, you want to get
    individual keystrokes from the input. There's no standard way to do
    that.

    See the FAQs:

    <http://c-faq.com/osdep/cbreak.html>




    Brian
    Default User, May 1, 2008
    #2
    1. Advertising

  3. NaN <> writes:
    > Hi I'm using Dev-C++.


    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>.

    --
    Keith Thompson (The_Other_Keith) <>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, May 1, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Angus
    Replies:
    2
    Views:
    708
    Andrew Koenig
    Jul 1, 2007
  2. MZ
    Replies:
    7
    Views:
    812
    Ed Mullen
    Mar 17, 2008
  3. Disc Magnet
    Replies:
    3
    Views:
    714
    David Thompson
    Mar 24, 2010
  4. Tilman
    Replies:
    0
    Views:
    403
    Tilman
    Mar 19, 2008
  5. Kevin

    CSS doesn't work on my <input>'s

    Kevin, Jun 8, 2010, in forum: Javascript
    Replies:
    4
    Views:
    282
    Thomas 'PointedEars' Lahn
    Jun 8, 2010
Loading...

Share This Page