bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 8, Problem 8.5E

(Character Testing) Write a program that inputs a character from the keyboard and tests it with each of the functions in the character-handling library. The program should print the value returned by each function.

Expert Solution & Answer
Check Mark
Program Plan Intro

Program Plan: 

  • mainfunction used to test all the functions.
  • Declare character type of variable character.
  • printf function used to print the formatted output on console.
  • scanf function used to takea formatted inputfrom console.

Program Description: 

The following program will input character and test all the character-handling library functions.

Explanation of Solution

Program: 

//header file included
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//included main function
intmain()
{
	//declare character type variable
char character;
//display message to user
printf("Enter the character:\n");
//input character
scanf("%c", &character);
//testing each function of character-handling library
//isdigit function
printf("'%c'%sdigit\n",character, isdigit(character)?"is a ":"is not a ");
//isalpha function
printf("'%c'%salphabet\n",character, isalpha(character)?"is a ":"is not a ");
//isalnum function
printf("'%c'%salpha-numeric\n",character, isalnum(character)?"is a ":"is not a ");
//isxdigit function
printf("'%c'%shexadecimal digit\n",character, isxdigit(character)?"is a ":"is not a ");
//islower function
printf("'%c'%slowercase letter\n",character, islower(character)?"is a ":"is not a ");
//isupper function
printf("'%c'%suppercase letter\n",character, isupper(character)?"is a ":"is not a ");
//toupper function
printf("The uppercase letter of '%c' is '%c'\n",character, toupper(character));
//tolower function
printf("The lowercase letter of '%c' is '%c'\n",character, tolower(character));
//isspace function
printf("'%c'%sspace\n",character, isspace(character)?"is a ":"is not a ");
//iscntrl function
printf("'%c'%scontrol character\n",character, iscntrl(character)?"is a ":"is not a ");
//ispunct function
printf("'%c'%sprinting character of ispunct\n",character, ispunct(character)?"is a ":"is not a ");
//isprint function
printf("'%c'%sprinting character of isprint\n",character, isprint(character)?"is a ":"is not a ");
//isgraph function
printf("'%c'%sprinting character of isgraph\n",character, isgraph(character)?"is a ":"is not a ");
//exiting from program
return 0;
}

Explanation:

In the above program, one character is inputted through scanf function. The %c is the format specifier used to input character type value. All the character-handling library function is used to test and print the output. The ternary operator is used inside the printf function to determine if the entered character is a digit, alphanumeric character, hexadecimal digit, lowercase letter or uppercase letter or not.

Sample Output:

  C How To Program, Student Value Edition Plus Myprogramminglab With Pearson Etext -- Access Card Package (8th Edition), Chapter 8, Problem 8.5E

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Show the output of the following code:
Fill in the blanks to rewrite the following statement: c. If x___________, then ________.
For each of the following statements, state whether it is True or False.

Chapter 8 Solutions

C How To Program, Student Value Edition Plus Myprogramminglab With Pearson Etext -- Access Card Package (8th Edition)

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Literals in Java Programming; Author: Sudhakar Atchala;https://www.youtube.com/watch?v=PuEU4S4B7JQ;License: Standard YouTube License, CC-BY
Type of literals in Python | Python Tutorial -6; Author: Lovejot Bhardwaj;https://www.youtube.com/watch?v=bwer3E9hj8Q;License: Standard Youtube License