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 192 views
1 answer 196 views
1 answer 247 views
1 answer 222 views
1 answer 186 views
1 answer 214 views
2 answers 219 views
...