c - 数组一致性 - 基础 C 编程

标签 c string numbers

我有一个字符串结构(姓名地址等)。

我需要确保第一个字符串(名称)中没有数字。我一直在尝试不同的方法,但都是徒劳。有什么帮助吗? :/

顺便说一句,我是新来的。非常感谢您的帮助。

最佳答案

您可以使用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
The isdigit 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/

相关文章:

python - 如何在python中将double保存到文件?

c++ - MPI_Isend 之后 MPI_Wait 的确切行为是什么?

c - 在 Sublime Text 3 中构建 C 文件并使用 fork();

java - 将字符串从数组拆分为另外 3 个时出现 ArrayIndexOutOfBoundsException

Python:如何将字符串 'ub' 添加到字符串中每个发音的元音前?

c - 在具有重复值的未排序数组中查找缺失的数字

使用 fork 创建子项并出现段错误(核心转储)

C 数据结构理论与技术 - 同栈中的整数和字符

python - 用python计算字母

ruby - Ruby 的 Number 类和 0 的便捷方法