0

I'm trying to check if an ISBN is valid in C. I want to ignore any array values that are not integers, so for instance ignoring - or blank spaces. I'm getting an error for the following section of code:

if(s[jj] == '-' || size[jj] == ' ') 

The error message is below:

error: subscripted value is neither array nor pointer

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 */
}
4

1 回答 1

1

Simple typo, size is not an array. It should be:

if(s[jj] == '-' || s[jj] == ' ')
                  ^^^
于 2014-02-19T02:45:09.440 回答