用C编程语言编写的isalnum()函数检查给定字符是否为字母数字。在ctype.h头文件中定义的isalnum()函数。
字母数字:一个字母或数字的字符。
句法:
int isalnum(int x);
例子:
Input : 1
Output : Entered character is alphanumeric
Input : A
Output : Entered character is alphanumeric
Input : &
Output : Entered character is not alphanumeric
// C code to illustrate isalphanum()
#include
#include
int main()
{
char ch = 'a';
// checking is it alphanumeric or not?
if (isalnum(ch))
printf("\nEntered character is alphanumeric\n");
else
printf("\nEntered character is not alphanumeric\n");
}
输出:
Entered character is alphanumeric
应用程序: isalnum()函数用于查找给定句子(或任何输入)中字母数字的数量。
例子:
Input: abc123@
Output: Number of alphanumerics in the given input is : 6
Input: a@#
Output: Number of alphanumerics in the given input is : 1
Input: ...akl567
Output: Number of alphanumerics in the given input is : 6
// C code to illustrate isalphanum()
#include
#include
int ttl_alphanumeric(int i, int counter)
{
char ch;
char a[50] = "www.geeksforgeeks.org";
ch = a[0];
// counting of alphanumerics
while (ch != '\0') {
ch = a[i];
if (isalnum(ch))
counter++;
i++;
}
// returning total number of alphanumerics
// present in given input
return (counter);
}
int main()
{
int i = 0;
int counter = 0;
counter = ttl_alphanumeric(i, counter);
printf("\nNumber of alphanumerics in the "
"given input is : %d", counter);
return 0;
}
输出:
Number of alphanumerics in the given input is : 19
想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。