C How To Program, Global Edition
C How To Program, Global Edition
8th Edition
ISBN: 9781292110974
Author: Paul Deitel, Harvey Deitel
Publisher: PEARSON
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, Global 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
(Even or Odd) Write a program that inputs a series of integers and passes them one at a timeto function isEven, which uses the remainder operator to determine whether an integer is even. Thefunction should take an integer argument and return 1 if the integer is even and 0 otherwise.
(Reversing Digits) Write a function that takes an integer value and returns the number withits digits reversed. For example, given the number 7631, the function should return 1367.
(Sort three numbers) Write the following function to display three numbers in increasing order: def displaySortedNumbers(num1, num2, num3): Write a test program that prompts the user to enter three numbers and invokes the function to display them in increasing order. Here are some sample runs:

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.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
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