我有一个字符串结构(姓名地址等)。
我需要确保第一个字符串(名称)中没有数字。我一直在尝试不同的方法,但都是徒劳。有什么帮助吗? :/
顺便说一句,我是新来的。非常感谢您的帮助。
最佳答案
您可以使用isdigit
来自 <ctype.h>
的函数.
#include <ctype.h>
/* Return 1 if the name is valid, 0 otherwise. */
int check_surname(const char *name)
{
for (int i = 0; name[i] != '\0'; i++)
{
if (isdigit((unsigned char)name[i]))
{
return 0;
}
}
return 1;
}
C11 (n1570), § 7.4.1.5 The
isdigit
function
Theisdigit
function tests for any decimal-digit character (as defined in 5.2.1).C11 (n1570), § 5.2.1 Character sets
the 10 decimal digits:
0 1 2 3 4 5 6 7 8 9
关于c - 数组一致性 - 基础 C 编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14161548/