isspace - C ctype.h

C examples for ctype.h:isspace

Type

function

From

<cctype> 
<ctype.h>

Description

Check if character is a white-space

For the C locale, white-space characters are any of:

Char Value Meaning
' ' (0x20) space (SPC)
'\t' (0x09) horizontal tab (TAB)
'\n' (0x0a) newline (LF)
'\v' (0x0b) vertical tab (VT)
'\f' (0x0c) feed (FF)
'\r' (0x0d) carriage return (CR)

Prototype

int isspace ( int c );

Parameters

Parameter Description
cCharacter to be checked, casted to an int, or EOF.

Return Value

A non zero value (i.e., true) if indeed c is a white-space character. Zero (i.e., false) otherwise.

Example

The following code prints out the C string character by character, replacing any white-space character by a newline character.

Demo Code

#include <stdio.h>
#include <ctype.h>
int main ()/*  www  . j  a va 2  s. c  o m*/
{
  char c;
  int i=0;
  char str[]="this is a test. Example \tsentence to test isspace\n";
  while (str[i])
  {
    c=str[i];
    if (isspace(c)) 
       c='\n';
    putchar (c);
    i++;
  }
  return 0;
}

Related Tutorials