Given a character, we have to check whether the given character is a whitespace character or not without using the library function.
Program:
The source code to check a given character is a whitespace character or not without using the library function is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.
// C program to check a given character is a whitespace character or not
// without using library function
#include <stdio.h>
int isWhiteSpace(char ch)
{
if ((ch == ' ') || (ch == '\t') || (ch == '\n') || (ch == 'v') || (ch == '\r') || (ch == '\f'))
return 1;
return 0;
}
int main()
{
char ch1 = ' ';
char ch2 = '\t';
char ch3 = 't';
if (isWhiteSpace(ch1))
printf("Given character is a whitespace character\n");
else
printf("Given character is not a whitespace character\n");
if (isWhiteSpace(ch2))
printf("Given character is a whitespace character\n");
else
printf("Given character is not a whitespace character\n");
if (isWhiteSpace(ch3))
printf("Given character is a whitespace character\n");
else
printf("Given character is not a whitespace character\n");
return 0;
}
Output:
Given character is a whitespace character
Given character is a whitespace character
Given character is not a whitespace character
Explanation:
In the above program, we created two functions isWhiteSpace() and main(). The isWhiteSpace() function is used to check the given character is a whitespace character or not.
In the main() function, we created three character variables ch1, ch2, ch3 that are initialized with ' ', '\t', 't' respectively. Then we checked given characters are whitespace characters or not by calling the isWhiteSpace() function and print the appropriate message on the console screen.
Given a character, we have to check whether the given character is a whitespace character or not without using the library function.
Program:
The source code to check a given character is a whitespace character or not without using the library function is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.
Output:
Explanation:
In the above program, we created two functions isWhiteSpace() and main(). The isWhiteSpace() function is used to check the given character is a whitespace character or not.
In the main() function, we created three character variables ch1, ch2, ch3 that are initialized with ' ', '\t', 't' respectively. Then we checked given characters are whitespace characters or not by calling the isWhiteSpace() function and print the appropriate message on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer