isgraphc() function in C
×


isgraphc() function in C

28

 The isgraph() function in C is utilized to determine if a character is a printable character other than a space.

 It belongs to the library, providing character classification functionalities.

 The isgraph() function in C is employed to discern whether a character is a printable character other than a space.

 It evaluates whether a character falls within the range of printable characters, excluding space (' ').

 This function is a part of the library, which furnishes functions for character classification.

Syntax of isgraph() in C:

int isgraph(int c);

Parameters:

 c: It's an integer representing a character.

Return Value:

 The isgraph() function returns an integer:

 It returns a non-zero value (usually 1) if the character c is a printable character other than a space.

 It returns 0 if the character c is not a printable character other than a space.


Examples:

1 Check if a Character is a Printable Character or not (Excluding Space):

// program to check if a character is a printable character or not
#include<stdio.h> 
#include<ctype.h> 

int main() {
    char ch = 'A';
    if (isgraph(ch)) {
        printf("%c is a printable character (excluding space)\n", ch);
    } else {
        printf("%c is not an printable (excluding space)\n", ch);
    }
    return 0;
}
	

Output:

A is a printable character (excluding space)

2Check if Characters in a String are Printable Characters (Excluding Space):

// program for checking if character in a string are printable character
#include<stdio.h> 
#include<ctype.h> 

int main() {
    char str[] = "Hello World!";
    for (int i = 0; str[i] != '\0'; ++i) {
        if (isgraph(str[i])) {
            printf("%c is a printable character (excluding space)\n", str[i]);
        } else {
            printf("%c is not an printable(excluding space)\n", str[i]);
        }
    }
    return 0;
}	

Output:

H is a printable character (excluding space)
e is a printable character (excluding space)
l is a printable character (excluding space)
l is a printable character (excluding space)
o is a printable character (excluding space)
  is not a printable character (excluding space)
W is a printable character (excluding space)
o is a printable character (excluding space)
r is a printable character (excluding space)
l is a printable character (excluding space)
d is a printable character (excluding space)
! is a printable character (excluding space)

3Count the Number of Printable Characters (Excluding Space) in a String:

// program to Count Number of Printable Characters (Excluding Space) in a String
#include<stdio.h>
#include<ctype.h> 

int main() {
    char str[] = "Hello World!";
    int c = 0;
    for (int i = 0; str[i] != '\0'; ++i) {
        if (isgraph(str[i])) {
            ct++;
        }
    }
    printf("No of character printable string (excluding space) : %d\n", c);
    return 0;
}
	

Output:

Number of printable characters (excluding space) in the string: 11


Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments