It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center。
7年前关闭。
我有一个字符串结构(名字,姓氏,地址等)。
我需要确保第一个字符串(名称)中没有数字。我一直在尝试不同的方法,但徒劳无功。有什么帮助吗? :/
顺便说一句,我是新来的。帮助非常感谢。
C11(n1570),第7.4.1.5节
C11(n1570),第5.2.1节字符集
10个十进制数字:
0 1 2 3 4 5 6 7 8 9
7年前关闭。
我有一个字符串结构(名字,姓氏,地址等)。
我需要确保第一个字符串(名称)中没有数字。我一直在尝试不同的方法,但徒劳无功。有什么帮助吗? :/
顺便说一句,我是新来的。帮助非常感谢。
最佳答案
您可以使用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节
isdigit
函数isdigit
函数测试是否有任何十进制数字字符(如5.2.1中所定义)。C11(n1570),第5.2.1节字符集
10个十进制数字:
0 1 2 3 4 5 6 7 8 9