cheader-filesoperands

Invalid Operands to binary / (have 'int *' and 'int')?


Every time I try this:

long crypt(int *integer)
{
    printf("Enter five digit integer:\n");  
    scanf("%i",integer);
    
    int digit1=integer/10000;
    int digit2=(integer%10000)/1000;
    int digit3=(integer%1000)/100;
    int digit4=(integer%100)/10;
    int digit5=(integer%10)/1;

    const char *digit1c[10];
    const char *digit2c[10];
    const char *digit3c[10];
    const char *digit4c[10];
    const char *digit5c[10];

    /...
}

(There's more but this seems to be the problem, I'll add the rest by request.)

then it return this error:

math2.h:44:20: error: invalid operands to binary / (have ‘int *’ and ‘int’)
math2.h:45:21: error: invalid operands to binary % (have ‘int *’ and ‘int’)
math2.h:46:21: error: invalid operands to binary % (have ‘int *’ and ‘int’)
math2.h:47:21: error: invalid operands to binary % (have ‘int *’ and ‘int’)
math2.h:48:21: error: invalid operands to binary % (have ‘int *’ and ‘int’)

I know it has something to do with the operators I used to initialize the digits and I did try changing their type to int * but that didn't work. So what's happening here exactly?


Solution

  • integer is a pointer to int (int*), so when you want to use the int it points to, you need to dereference it:

    int digit1=(*integer)/10000; // and so on...