有没有办法编程循环来遍历c​​har*数组中的每个字符?

Joh*_*eda -2 c c++ arrays

我想知道是否有一种方法或方法来检查数组中的单个字符

char* s[size] = {
    "0-2324-2324-7", 
    "032121353X", 
    "0-619-66248-X", 
    "0-758-50938-6", 
    "0870495275"
};
Run Code Online (Sandbox Code Playgroud)

我想我必须编写遍历数组中每个条目的for循环和遍历数组内该条目中每个字符的for循环

有点像:

for (int i=0;i<size;i++) 
    for (int j=0; j<"size of s[i]"; j++)  // the size of an entry so "032121353X" would be 10
        int* c= "the j character in s[i]" // assigns c the individual character in s[i]
        if(c<='0'||c>='9')  // checks if its a digit
Run Code Online (Sandbox Code Playgroud)

Bar*_*rry 5

你实际上并不需要strlen遍历一个字符串 - 因为无论如何你都在迭代它,我们可以通过走路来避免双重迭代,直到我们击中它们\0:

for (int i = 0 ; i < size ; ++i)
{
    // Checking for *p is equivalent to checking if p != '\0'
    // This works because of the nature of C
    for (char* p = s[i]; *p; ++p) 
    {
        if (*p >= '0' && *p <= '9') 
        {
            // I have a digit!
        }
    }
}
Run Code Online (Sandbox Code Playgroud)