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 291 views
1 answer 296 views
1 answer 351 views
1 answer 307 views
1 answer 278 views
1 answer 300 views
2 answers 326 views
...