Closed. This question is off-topic。它当前不接受答案。
想改善这个问题吗? Update the question,因此它是on-topic,用于堆栈溢出。
5年前关闭。
我正在尝试检查ISBN在C中是否有效。我想忽略不是整数的任何数组值,例如忽略-或空格。以下代码部分出现错误:
错误消息如下:
错误:下标值既不是数组也不是指针
...
想改善这个问题吗? Update the question,因此它是on-topic,用于堆栈溢出。
5年前关闭。
我正在尝试检查ISBN在C中是否有效。我想忽略不是整数的任何数组值,例如忽略-或空格。以下代码部分出现错误:
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 */
}
最佳答案
简单的错字,size
不是数组。它应该是:
if(s[jj] == '-' || s[jj] == ' ')
^^^
关于c - 检查ISBN在C语言中是否有效,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21869961/
10-15 00:49