Introduce function package
#include "stdio.h"#include "string.h"
In tc2.0, the header file of the library function is in the TC/include directory, and the system function is in the TC/lib directory. If these function files cannot be found, you can perform the following settings in option/directories:
Include directories {TC2 directory}/includeinclude directories {TC2 directory}/lib
1. Standard Input/Output Functions
Introduce the header file stdio. h
Input Device: Mouse, keyboard, camera, etc.
Output devices: files, screens, empty devices (NUL), etc.
Input Function: scanf ()
Output Function: printf ()
2-character functions and string processing functions
Character function file: ctype. H. It is mainly used to identify ASCII letters, control characters, punctuation marks, and case-sensitivity conversion.
String function file: String. H. It is mainly used for string copying, connection, searching, and substring processing.
/* Character Statistics */# include <stdio. h> # include <math. h> main () {int num = 0, cntrl_num = 0, else_num = 0; char ch; printf ("character statistics/n "); printf ("Enter the character (CTRL + Z):"); While (CH = getchar ())! = EOF) {If (iscntrl (CH) {/* determine whether it is a control character */cntrl_num ++;} else if (isdigit (CH )) {/* determine whether it is a number */num ++;} else {/* Other characters */else_num ++ ;}} printf ("control characters: % d/N", cntrl_num); printf ("number: % d/N", num ); printf ("other characters include % d/N", else_num );}
In the program, the getchar () function is used to obtain a character input from the keyboard. EOF is a constant (EOF =-1) defined in stdio. H. It is usually used to determine whether the file has ended. Press the keyboard to enter the time table Ctrl + z key combination.