C run-time library function __isascii&iswascii& __toascii

Source: Internet
Author: User
Tags printf linux

Determines whether a particular character is a ASCII character.

int __isascii(
int c
);
int iswascii(
wint_t c
);

Test program:

#include "stdafx.h"
#include "ctype.h"
#include "locale.h"
#include "stdio.h"

void CheckCharAndPrint(char acChar)
{
if(__isascii(acChar))
{
printf("char %c is a ascii char.\n",acChar);
}
else
{
// 此处无法正常输出中文,没有深入研究了
printf("char %c is not a ascii char.\n",acChar);
}
}

void CheckWCharAndPrint(wchar_t awcChar)
{
if(iswascii(awcChar))
{
wprintf(L"wchar %c is a ascii char.\n",awcChar);
}
else
{
setlocale(LC_ALL,"");
wprintf(L"wchar %c is not a ascii char.\n",awcChar);
}
}

int _tmain(int argc, _TCHAR* argv[])
{
char lcC = 'a';
char lcD = '中';

CheckCharAndPrint(lcC);
CheckCharAndPrint(lcD);

wchar_t lwcC = L'a';
wchar_t lwcD = L'中';

CheckWCharAndPrint(lwcC);
CheckWCharAndPrint(lwcD);

return 0;
}

Description

__isascii is a special function because it starts with two front underscores. This is not uncommon in C language. (at least I see less)

This function should not belong to the standard library function, which is not described in the C language reference in "Tcpl", but is available in GCC. In other words, Linux can also use this function normally.

Iswascii the wide-byte version of this __isascii function, like many wide-byte versions of functions, this function belongs to Ms itself, so. Linux can not use this function, to use, you can only achieve ROM.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.