我正在尝试检查ISBN中的ISBN是否有效。我想忽略任何非整数的数组值,例如忽略 - 或空格。我在以下代码部分收到错误:
if(s[jj] == '-' || size[jj] == ' ')
错误信息如下:
错误:下标值既不是数组也不是指针
int checkISBN( char s[] ) {
int result = 0;
int theSize = 18; /* Most ISBNs are 10 digits long, with some being
* 13. I just chose 18 incase there are a lot of
* blank spaces or dashes in the array. */
int n = 1; /* This comes in handy for determing if the check
character is valid. */
int sum = 0; /* We divide this value by 11 to determine if the
check character is valid */
int jj;
for (jj = 0; jj sum += s[i] * n; ++n;
/* For the below, the formula works like this:
* The sum for the ISBN 0-8065-0959-7 is
1*0 + 2*8 + 3*0 + 4*6 + 5*5 + 6*0 + 7*9 + 8*5 + 9*9 = 249
* The remainder when 249 is divided by 11 is 7, the last
* character in the ISBN. The check character is used to
* validate an ISBN.
* */
...
}
...
int checkCharacter = sum / 11;
if (checkCharacter == s[size-1]) {
result = 1;
/* I know this part is wrong.
* If the array only contains 10 values, then s[17] will be null.
* I'll fix this later.
* */
return result;;
/* Fix this to return a calculated value based on string */
}
答案 0 :(得分:1)
简单错字,size
不是数组。它应该是:
if(s[jj] == '-' || s[jj] == ' ')
^^^