C How to Program (8th Edition)
C How to Program (8th Edition)
8th Edition
ISBN: 9780133976892
Author: Paul J. 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 (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
(Rounding Numbers) An application of function floor is rounding a value to the nearestinteger. The statementy = floor(x + .5);will round the number x to the nearest integer and assign the result to y. Write a program that readsseveral numbers and uses the preceding statement to round each of these numbers to the nearestinteger. For each number processed, print both the original number and the rounded number.
(C++ language)
(Replace strings) Write the following function that replaces the occurrence of a substring old_substring with a new substring new_substring in the string s. The function returns true if string s is changed, and otherwise, it returns false. bool replace_strings (string& s, const string& old_string, const string& new_string) Write a test program that prompts the user to enter three strings, i.e., s, old string, and new_string, and display the replaced string.

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