Register | Sing In

New posts

Stacks in C programming Linked Lists in C programming File Input/Output in C programming Check prime numbers in C Programming C Programming Enumeration C Programming Union

Archives

2013-10 2013-09 2013-08

C library functions - isprint and isgraph

September 6, 2013 Posted by: GPA Views: 632 0 comments

Problem

C library function - isprint() and isgraph(). Write simple application using these two functions.

Solution

This function isprint checks if a character can be displayed on the screen (including the space character). Function isgraph is the same as isprint, the space character is not included in this case. You should include <ctype.h> library.

Declaration:

int isprint(int value); 

int isgraph(int value);  

where value is the character to be checked. 

First function returns 1 (true) if value is a printing character including a space (' ') and returns 0 (false) otherwise.

Second function returns 1 (true)  if value is a printing character other than a space (' ') and returns 0 (false) otherwise. 

Example:

   

#include <stdio.h>
#include <ctype.h>
int main(int argc, char *argv[])
{
   int isprintvalue1='g';
   int isprintvalue2='\t';
   int isgraphvalue1='g';
   int isgraphvalue2=' ';
 
  printf("globalproganswer.com\n");  
  //call function isprint
   printf("isprint function tests:\n");
   if(isprint(isprintvalue1)) {
      printf("isprintvalue1 is a printing character\n");
   } else {
      printf("isprintvalue1 is not a printing character\n");
   }
   if(isprint(isprintvalue2)) {
      printf("isprintvalue2 is a printing character\n");
   } else {
     printf("isprintvalue2 is not a printing character\n");
   }
   printf("\nisgraph function tests:\n");
   //call function isgraph
   if(isgraph(isgraphvalue1)) {
       printf("isgraphvalue1 is a printing character other than a space\n");
   } else {
       printf("isgraphvalue1 Space is not a printing character other than a space\n");
   }  
   if(isgraph(isgraphvalue2)) {
      printf("isgraphvalue2 is a printing character other than a space\n");
   } else {
     printf("isgraphvalue2 is not a printing character other than a space\n");
   }
  system("PAUSE");//delay
   return 0;
}

Output

C library functions - isprint and isgraph

Download this example

0 Comments...

Leave a Reply

Please, Sing In to leave a Reply for this material.



Online Chat

LiveZilla Live Help

Popular posts

Function strtok in C programming Check prime numbers in C Programming C Programming Union Linked Lists in C programming File Input/Output in C programming C Programming Enumeration

RSS-subscribe

New materials

Subscribe