EasyManuals Logo
Home>Casio>Desktop>Z-1

Casio Z-1 User Manual

Casio Z-1
126 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #90 background imageLoading...
Page #90 background image
90
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:
Char=B Hex=0x42
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 Hex=0x%x¥n“,c,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. . .
Q
Char=Q Hex=0x51
>_
This shows that the character code for “Q” is hexadecimal 51.

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Casio Z-1 and is the answer not in the manual?

Casio Z-1 Specifications

General IconGeneral
BrandCasio
ModelZ-1
CategoryDesktop
LanguageEnglish

Related product manuals