How to determine if a character is whitespace in C

1 Answer

0 votes
#include <stdio.h> 
#include <ctype.h> 

int main(void)
{   
	char ch = 'a';
	if (isspace(ch))
		printf("yes\n");
	else
		printf("no\n");

	ch = ' ';
	if (isspace(ch))
		printf("yes\n");
	else
		printf("no\n");
        
    ch = '\n';
	if (isspace(ch))
		printf("yes\n");
	else
		printf("no\n");
        
    ch = '\t';
	if (isspace(ch))
		printf("yes\n");
	else
		printf("no\n");

    return 0;
}

   
/*
run:

no
yes
yes
yes

*/

 



answered Dec 7, 2016 by avibootz

Related questions

1 answer 182 views
1 answer 189 views
1 answer 233 views
1 answer 207 views
1 answer 176 views
1 answer 205 views
2 answers 205 views
...