为什么有错误C2100:非法间接 [英] why is there error C2100: illegal indirection

查看:199
本文介绍了为什么有错误C2100:非法间接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <stdio.h>

//function declaration
void dispTariff(float);
float getTariff(int);

//declare and initialize data
int eusage[]={800,650,525,450,420,405,400,400,400,400};
#define tariff 25;
void main(void)
{
	float usageA,usageB,increase;
	usageA=getTariff(5);
	usageB=getTariff(8);
	increase=((usageB-usageA)/usageA*100);

	//print increase in percentage
	printf("increase in percentage is %2.2f%%\n",increase);

}//main
float getTariff(int duration)
{
	int j=0;
	float ebill=0;
	for(j=0,j<duration;j++;)>
	{
		ebill=ebill+tariff*(eusage[j]/1000.0);
	}
	printf("total bill after 6 hours %.2fcent\n",ebill);
	return ebill;
}

推荐答案

错误来源在这里:

The error source is here:
#define tariff 25;



预处理器将用 25替换<​​code>关税的出现; 以便编译器稍后看到这一行:


The preprocessor will replace the occurence of tariff with 25; so that the compiler later sees this line:

ebill=ebill+25;*(eusage[j]/1000.0);



分号定义表达式的结尾, *(eusage [j] /1000.0)被解释为间接运算符的另一个表达式(*)应用于非指针值。

因此将其更改为:


The semicolon defines the end of an expression and *(eusage[j]/1000.0) is interpreted as another expression where the indirection operator (*) is applied to a non-pointer value.
So change it to:

#define tariff 25





但是你的代码中还有另一个错误。线路



But there is also another error in your code. The line

for(j=0,j<duration;j++;)



应该是


should probably be

for(j=0;j<duration;j++)


这篇关于为什么有错误C2100:非法间接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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