📖 Samacheer Kalvi · 11th TN - English Medium · Computer Science · Page 186question

Introduction to C++ · Part 2

Chapter 3: 4 · Computer Science

The predefined function getchar() is used to get a single character from keyboard and putchar() function is used to display it. #include<iostream> #include<stdio.h> using namespace std; int main() cout<<"\n Type a Character : "; char ch = getchar(); cout << "\n The entered Character is: "; putchar(ch); return ; Output: Type a Character : T The entered Character is: T Program . C++ code to accept a character and display it . .

. . gets() and puts() functions Function gets() reads a string from standard input and stores it into the string pointed by the variable. Function puts() prints the string read by gets() function in a newline.

Chapter Page - - #include<iostream> #include<stdio.h> using namespace std; int main() char str[ ]; cout<<"Enter a string : "; gets(str); cout<<"You entered: " puts(str); return( ); Output : Enter a string : Computer Science You entered: Computer Science Program . C++ code to accept and display a string . . Character functions (ctype.h) This header file defines various operations on characters.

Following are the various character functions available in C++. The header file ctype.h is to be included to use these functions in a program. . .

. .isalnum() This function is used to check whether a character is alphanumeric or not . This function returns non-zero value if c is a digit or a letter, else it returns . General Form: int isalnum (char c) Example : int r = isalnum(‘ ’); cout << isalnum('A') <<’\t’<<r; But the statements given below assign to the variable n, since the given character is neither an alphabet nor a digit.

char c = '$'; int n = isalnum(c); cout<<c; Output: Chapter Page - - #include<iostream> #include<stdio.h> #include<ctype.h> using namespace std; int main() char ch; int r; cout<<"\n Type a Character :"; ch = getchar(); r = isalnum(ch); cout<<"\nThe Return Value of isalnum(ch) is :"<<r; Output- : Type a Character :A The Return Value of isalnum(ch) is : Output- : Type a Character :? The Return Value of isalnum(ch) is : Program . . .

. . isalpha() The isalpha() function is used to check whether the given character is

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →