I am given a task to write a code that check whether the user input is a white-space character or not. If the input character is a white-space: Print "white-space character" If the input character is not a white-space: Print "not a white-space character" We are currently learning the "ctype.h" library, and learned about it many functions for characters. So I decided to use "isspace()" function in my code since it asking me to check whether the user input is a white-space character or not. Here is my code:
#include <stdio.h>
#include <ctype.h>
int main(){
char a;
int output;
printf("Enter a character: ");
scanf("%c", &a);
printf("%c",a);
output = isspace(a);
if (output == 0)
{
printf("Not a white-space character.");
}
else
{
printf("White-space character.");
}
return 0;
}
However, when I execute the code, I keep recieving that the white-space character such as "\t and "\n" are "not white-character". I noticed that the scanf, when I input "\n" it is only reading the "\" and not "\" and "n" together. I have not learn bool or string part of the code yet, our professor hasn't teached it to us yet so I can't not use those code. So if there is any other way, by not using that, please let me know! Thank you o/