Tutorial Gateway

  • C
  • C#
  • Python
  • SQL
  • Java
  • JS
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs
  • MySQL

isspace in C Programming

The C isspace function is one of the Standard Library Functions available in C programming, which is useful to check the given character is a space or not. The basic syntax of the isspace in C Programming language is as shown below.

The below C isspace function function will accept a single character as the parameter, and find whether the given character is a space or not.

isspace(char)

isspace in C Programming Example 1

The isspace function used to find whether the given character is a space character or not.

//Example for isspace in C Programming
#include <stdio.h>
#include <ctype.h>

int main()
{
    char ch = ' ';
    
    if(isspace(ch))
    {
        printf("The Character ch is a Space Character \n");
    }
    else
    {
        printf("The Character ch is Not a Space Character \n");
    }
    return 0;
}

isspace in C programming 1

isspace in C Programming Example 2

This C program allows the user to enter any character, and check whether the character is space or not using the isspace function.

//Example for isspace in C Programming
#include <stdio.h>
#include <ctype.h>

int main()
{
    char ch;
    printf("Please Enter Any Valid Character : \n");
    scanf("%c", &ch);

    if(isspace(ch))
    {
      printf("\n You have entered a Space Character");         
    }
    else
    {
      printf("\n %c is not a Space Character", ch);
      printf("\n I request you to enter Space Character");	
    }
}
isspace in C programming 2

Let me enter the Uppercase letter

isspace in C programming 3

First, we declared a character variable called ch.

char ch;

The first C Programming statement will ask the user to enter any character. And then we are using the scanf to assign the user entered character to ch variable

printf("Please Enter Any Valid Character : \n");
scanf("%c", &ch);

Next, we used the If Statement to check whether the character is space, or not using isspace function. If the condition is True, then the following statement will be printed

printf("\n You have entered a Space Character");

If the above condition is FALSE, then the given character is not space. So, it will print below statements

printf("\n %c is not a Space Character", ch);
printf("\n I request you to enter Space Character");

Without using isspace Example

This C program allows the user to enter any character, and check whether the character is space or not using the ASCII table. Here we don’t use the built-in function isspace.

//Example for isspace in C Programming
#include <stdio.h>
#include <ctype.h>

int main()
{
    char ch;
    printf("Please Enter Any Valid Character : \n");
    scanf("%c", &ch);

    if(ch == 32)
    {
      printf("\n You have entered a Space Character");         
    }
    else
    {
      printf("\n %c is not a Space Character", ch);
      printf("\n I request you to enter Space Character");	
    }
}
C isspace example 1

Since 32 is the ASCII value for space, we replaced the C isspace function with 32. I suggest you cross-check the ASCII table. Let me try another value

C isspace example 2

Filed Under: C Programming

  • C Comments
  • C Escape Sequence
  • C Programming Operators
  • C Arithmetic Operators
  • C Assignment Operators
  • C Bitwise Operators
  • C Conditional Operator
  • C Increment & Decrement Optr
  • C Logical Operators
  • C Relational Operators
  • C Sizeof Operator
  • C If Statement
  • C IF ELSE Statement
  • C Else If Statement
  • C Nested If
  • C Break Statement
  • C Continue Statement
  • C Goto Statement
  • C Switch Case
  • C For Loop
  • C While Loop
  • C Do While Loop
  • C Arrays
  • C Two Dimensional Array
  • C Multi Dimensional Array
  • C String
  • C Structures
  • C Nested Structures
  • C Array of Structures
  • C Structures and Functions
  • C Union
  • C Structure & Union differences
  • C Pointers
  • C Pass Pointers to Functions
  • C GETS
  • C fgets Function
  • C fgetc
  • C fputs function
  • C fputc
  • C Functions
  • C Types of Functions
  • C Pass Array to Functions
  • Call By Value & Call By Reference
  • C Recursion
  • C Program Examples

Copyright © 2021· All Rights Reserved by Suresh.
About | Contact | Privacy Policy