2014-02-01 4 views
-1

Я застрял в этой части, и мне нужна помощь в исправлении ошибок компиляции в приведенном ниже коде. Я использую компилятор g ++.неверное преобразование char * в int

Сообщение об ошибке выглядит следующим образом: "недопустимое преобразование из Àconst полукокса * â до âintâ [-fpermissive]"

bool isRegistered(const Prefix* pre,int area,const char* publisher, int * pos) 
{ 
int n,i=0,num,flag=0,low,high,pub; 
n=*(pos); 
while(pre->area[n]==area) 
{ 
num=publisher[i]-48; 

switch(pre->pubLen[n]) 
{ 
case 1: 

num=publisher[i]-48; 

Проблема снижается ниже в каждом конкретном случае.

low=((*pre).pubLow[n])-48; 
high=(pre->pubHigh[n])-48; 
if((num>low)&&(num<high)) 
{ 
pub=num; 
} 
break; 

case 2: 
num=(publisher[i]-48)*10+(publisher[i+1]-48); 
low=(pre->pubLow[n])-48; 
high=(pre->pubHigh[n])-48; 
if((num>low)&&(num<high)) 
{ 
pub=num; 
} 
break; 

Определение Prefix

struct Prefix { 
    int no;    // number of entries 
    int area[MAX];  // area elements 
    char pubLow[MAX][8]; // low end of publisher range 
    char pubHigh[MAX][8]; // high end of publisher range 
    int pubLen[MAX]; // no of chars in publisher string 
}; 

Case 3 и так далее ....

+0

Можете ли вы показать строка, которая дала ошибку? – Brian

+0

Вам нужна помощь в написании кода, а не его отладке –

+0

Эти две строки дают ошибку. низкий = ((* pre) .pubLow [n]) - 48; high = (pre-> pubLow [n]) - 48; –

ответ

0

Дайте определение pubLow

Также

**low=((*pre).pubLow[n])-48; 
high=(pre->pubLow[n])-48; ** 

низко представляет собой целое число, удалить ** до того низко и после 48; Такое, что он становится

low=((*pre).pubLow[n])-48; 
high=(pre->pubLow[n])-48; 

Вот ваш код

bool isRegistered(const Prefix* pre,int area, char* publisher, int * pos) 
{ 
int n,i=0,num,flag=0,low,high,pub; 
n=*(pos); 
while(pre->area[n]==area) 
{ 
num=publisher[i]-48; 

switch(pre->pubLen[n]) 
{ 
case 1: 

num=publisher[i]-48; 
    low=atoi(((*pre).pubLow[n])-48); 
high=atoi((pre->pubHigh[n])-48); 
if((num>low)&&(num<high)) 
{ 
pub=num; 
} 
break; 

case 2: 
num=(((publisher[i]-48)*10)+(publisher[i+1]-48)); 
low=atoi((pre->pubLow[n])-48); 
high=atoi((pre->pubHigh[n])-48); 
if((num>low)&&(num<high)) 
{ 
pub=num; 
} 
break; 
+0

По-прежнему отображается ошибка. То же самое –

+0

Проверьте отредактированный код – Hamza

Смежные вопросы