Re: [cc65] Get user input?

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2004-09-25 00:17:12
On Fri, Sep 24, 2004 at 05:56:29PM -0400, Raj Wurttemberg wrote:
> What is the simplest way to get user input with cc65 on a C64? I would like
> to know how to get a line of input from a user, like the "input" command in
> C64 basic.

To just get one line of input:

        char buf [40];
        printf ("Your input: "); fflush (stdout);
        fgets (buf, sizeof (buf), stdin);
        printf ("\nYour input was: %s\n", buf);

To input a number and check for correct input:

        char buf [40];
        int number;
        printf ("Input a number: "); fflush (stdout);
        fgets (buf, sizeof (buf), stdin);
        if (sscanf (buf, " %d", &number) == 1) {
            printf ("\nYour input was: %d\n", number);
        } else {
            /* Input is not a number */
            printf ("\n?REDO FROM START\n");
        }

If you don't need full BASIC compatibility, you may replace the error message
by something like "Input is not a number":-)

> Just curious... Is the scanf() function being worked on? I'm still plugging
> away at my "C by Example" book. I bought the book in 1993 and just _now_ got
> around to opening it! haha! :)

The guts of the scanf family of functions are already available and based on
it, the sscanf function is there and should work (apart from the usual
bugs:-).

scanf and fscanf are special in that they do not only need the parsing (like
sscanf), but must be able to place one character back onto the input stream,
in case the character just read was wrong. In other words: The main
functionality is already available, but these two functions need the ungetc
function, and this function was not available in version 2.10. It has been
added in the development version. Adding scanf and fscanf should be easy now,
but must still be done.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sat Sep 25 00:17:17 2004

This archive was generated by hypermail 2.1.8 : 2004-09-25 00:17:26 CEST