The GetChar() function in the Ring programming language

Hello

The GetChar() function accept one character from the keyboard buffer

In this example

While True
        See "
                Main Menu
                (1) Say Hello
                (2) Exit
            "
        Option = GetChar()
        GetChar() GetChar()  # End of line
        # the previous two lines can be replaced with the next line
        # Give Option

        if Option = 1
                see "Enter your name : " give cName
                see "Hello " + cName
        else
                bye
        ok
End

We uses GetChar() Three times
The first time we get the user option

Option = GetChar()

 

But in the second and the third time (We accept the new line characters from the buffer)

GetChar() GetChar()  # End of line

Example : when the user select the option number 1 then press ENTER
We have Three Characters
The first character is : Number 1
The second character is : CHAR(13)
The third character is : CHAR(10)
because Windows uses CHAR(13) and CHAR(10) for new each line  ( i.e. CR+LF )

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s