void* checkRow(void* in)
{
//pthread_mutex_lock(&count_mutex);
parameters* temp = (parameters*) in;
int row = temp->row;
int col = temp-> col;
int i = 0;
int j = 0;
for (i = row; i < SIZE; i++)
for (j = col; j< SIZE; j++)
{
printf("%d ", isdigit(temp->arr[i][j]));
if(isdigit(temp->arr[i][j]) && temp->arr[i][j] <= SIZE)
{
//pthread_mutex_unlock(&count_mutex);
return (void*) 1;
}
}
return (void*) 0;
}
出于某种原因,我尝试运行 isdigit(temp->arr[i][j])
时总是返回 false 而不是 true。该数组是用所有数字初始化的。我在数组上运行了 printf,它表明数组返回的结果是正确的,所以我不知道为什么 isdigit 不能将数组的元素识别为数字。
数组是结构体的成员
typedef struct
{
int row;
int col;
int arr[SIZE][SIZE];
}parameters;
最佳答案
isdigit(int)
需要在 unsigned char
或 EOF
范围内的值,否则为未定义行为。如果 char
已签名,则使用负 char
值的 isdigit(int)
是有问题的。
isdigit(int)
当值在 '0'
... '9'
范围内时返回 true。这些辅音的数值通常为 48 到 57",但它取决于字符集 - ASCII 是最常见的。这 10 个值必须是连续的。
要将数字转换为文本数字,请使用 x + '0'
要测试文本数字并避免使用范围有限的 isdigit()
,请使用:
int test_isdigit(int x) {
return x >= '0' && x <= '9';
}
这是可移植的。
关于c - 是数字在 int 数组元素上不返回 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32998938/