Entering Characters And Values - Casio FX-890P Owner's Manual

Casio personal computer owner's manual
Table of Contents

Advertisement

6.2.3 Entering characters and values

Entering a single character from the keyboard
Here we will create a program that outputs a character and its corresponding
character code in hexadecimal format. If you press the key for the letter "B", for
example, the format will be:
The standard function getchar() is used to tell the computer to get one character
input from the keyboard. In most ANSI C compilers, this function is part of the
standard input / output library which complements the core of C language. You need
then to include this library with the following statement:
#include "stdio.h"
If you use mathematical functions, which are again not in the historical core of C
language, you need to include the mathematical library:
#include "math.h"
The C interpreter of your pocket computer does not need these instructions for a
compiler. Nevertheless, it is a good idea to add a comment reminding the need for
the standard libraries to help portability.
The following is the program that will accomplish our task:
/* Diplay character codes */
/* #include <stdio.h> */
main(){
int c;
c=getchar();
printf("Char=%c
}
The getchar() function only returns the character code, and so no argument is used
inside of the parenthesis. In the printf() function, %c specifies character format while
%x specifies hexadecimal format.
Try inputting and executing this program.
When you enter the RUN command, the interpreter executes the program until it
comes to the getchar() function. At that time, execution stops and the cursor flashes
at the bottom of the display waiting for further input. At this time, you should enter a
letter, number or symbol. The following shows the display that should result if you
enter the letter "Q".
.R U N .
.
.Q.
.
.
This shows that the character code for "Q" is hexadecimal 51.
Char=B Hex=0x42
Hex=0x%x¥n",c,c);
Q
Char=Q
>_
90
Hex=0x51

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Z-1grZ-1

Table of Contents