【发布时间】:2016-01-05 01:56:32
【问题描述】:
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;
【问题讨论】:
-
数组被初始化为所有数字。您是否使用
1之类的数字或'1'之类的字符来初始化它们?您需要使用后者而不是前者才能让isdigit()返回 true。 -
我用整数初始化它。
-
这就是问题所在。您可以通过添加
'0'将数字转换为它们的字符表示。 -
哦,我明白了,那我想我会尝试不同的方法
-
在这个
if(isdigit(temp->arr[i][j]) && temp->arr[i][j] <= SIZE)中,您将char范围检查与int范围检查混合在一起。为什么不写if(temp->arr[i][j] > 0 && temp->arr[i][j] <= SIZE)?