无效的二进制操作数/(具有"int *"和"int")? [英] Invalid Operands to binary / (have 'int *' and 'int')?

查看:669
本文介绍了无效的二进制操作数/(具有"int *"和"int")?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我尝试以下方法:

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.)

然后返回此错误:

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’)

我知道它与我用来初始化数字的运算符有关,我确实尝试将其类型更改为"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?

推荐答案

integerint(int*)的指针,因此,当您要使用int时,它会指向到,您需要取消引用:

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...

这篇关于无效的二进制操作数/(具有"int *"和"int")?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆