Header file:
wctype.h
Synopsis:
wctype_t wctype(const char *property)
Description:
It will provide the property descriptor based on the "property" value. Some of the known properties are alnum, alpha, cntrl, digit, graph, lower, print, punct, space, upper, xdigit.
Return Value:
returns a property descriptor on success. 0 on failure.
Sample Program for wctype in C:
#include <stdio.h>
#include <wchar.h>
#include <wctype.h>
int main() {
wctype_t a;
wint_t wide_char;
char input;
a = wctype("digit");
printf("Enter your input:");
input = getchar();
/* btowc -Converts character to wide character format */
wide_char = btowc(input);
if (iswctype(wide_char, a))
printf("It is a digit\n");
else
printf("It is not a digit\n");
printf("Return value: %d\n", iswctype(wide_char, a));
return 0;
}
#include <wchar.h>
#include <wctype.h>
int main() {
wctype_t a;
wint_t wide_char;
char input;
a = wctype("digit");
printf("Enter your input:");
input = getchar();
/* btowc -Converts character to wide character format */
wide_char = btowc(input);
if (iswctype(wide_char, a))
printf("It is a digit\n");
else
printf("It is not a digit\n");
printf("Return value: %d\n", iswctype(wide_char, a));
return 0;
}
Output:
Enter your input:1
It is a digit
Return value: 1
It is a digit
Return value: 1
No comments:
Post a Comment