LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 07-17-2007, 03:03 AM   #1
teoporta
LQ Newbie
 
Registered: Jul 2007
Posts: 2

Rep: Reputation: 0
about C++ invalid conversion from 'const char*' to 'char'


Hi,
trying to do something in C++ I fount this error: invalid conversion from 'const char*' to 'char'.

I show you the extract of the program with the error.

M=smth, N=smth;
char *numero="0";
switch (mappa[M][max_r-N][0])
{case 1: *numero=" 1"; //error
case 2: *numero=" 2"; //error
case 3: *numero=" 3"; //error
case 4: *numero=" 4"; //error
case 5: *numero=" 5"; //error
case 6: *numero=" 6"; //error
case 7: *numero=" 7"; //error
case 8: *numero=" 8"; //error
}
 
Old 07-17-2007, 06:26 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
What are the declarations of variables mappa and max_r? That will probably show the problem.

Last edited by wjevans_7d1@yahoo.co; 07-17-2007 at 06:28 AM.
 
Old 07-17-2007, 08:21 AM   #3
teoporta
LQ Newbie
 
Registered: Jul 2007
Posts: 2

Original Poster
Rep: Reputation: 0
max_r and mappa[][][] are numbers defined...

here's alla the program


#include<iostream.h>
#include<time.h>
#include <passe_par_tout.h>
#include<stdlib.h>
# define DIM 30

int bomba,r,c,max_c,max_r,mappa [DIM][DIM][2],andare_di_accordo,o,q,s;
double z[2];

int controllo (int mappa [DIM][DIM][2], int max_c, int max_r, int bomba)
{
int r,c,k=0;
for (r=0;r<max_r;r++)
{
for (c=0;c<max_c;c++)
{
if (mappa[r][c][0]==9) k++;
}
}
if (!(k-bomba)) return (1);
else
{
for (r=0;r<max_r;r++)
{
for (c=0;c<max_c;c++) mappa [r][c][0]=0;
}
}
return (0);
}
//-------------------------------------------------------------------------------------------
void leggimappa (int mappa[DIM][DIM][2])
{
int i,j,k,p,l;

for(i=0;i<bomba;i++)
{
p=random();
l=random();
r=(p/2147483647.)*(max_r);
c=(l/2147483647.)*(max_c);

mappa [r][c][0]=9;
}

if (!controllo(mappa, max_r, max_c, bomba)) leggimappa (mappa);

for (r=0;r<max_r;r++)
{
for (c=0;c<max_c;c++)
{
k=0;
for (i=r-1;i<=r+1;i++)
{
for (j=c-1;j<=c+1;j++)
{
if (i>=0 && i<max_r && j>=0 && j<max_c && (i!=r || j!=c))
{
if (mappa[i][j][0]==9) ++k;
}
}
}
if (mappa [r][c][0] !=9) mappa [r][c][0]=k;
}
}
return;
}
//-------------------------------------------------------------------------------------------
void disegnamappa1 (int mappa[DIM][DIM][2])
{
int r,c;

for (r=0;r<max_r;r++)
{
for (c=0;c<max_c;c++)
{
cout<<mappa[r][c][0];
}
cout<<endl;
}
return;
}
//-------------------------------------------------------------------------------------------
void lamappa (int mappa[DIM][DIM][2])
{
cout<<"Quanto vuoi grande il campo? (n righe,colonne)\n";

cin>>max_r;
cin>>max_c;

char *stringa="minato!";
int X,Y;

double xmin=0, ymin=0, xmax=max_c, ymax=max_r;

X=(max_c*16);
Y=(max_r*16);
m_startg(stringa,&X,&Y);
X=100;
Y=100;
m_window(&X,&Y);
m_frame(&xmin,&ymin,&xmax,&ymax);

int r,c;
X=1,Y=1;
m_use_as_pixmap(&X,&Y);
int K;
char *b="nulla.ppm";
for (r=0;r<max_r;r++)
{
for (c=0;c<max_c;c++)
{
int a[]={r*16,c*16,0,0,max_r,max_c,0};
m_load_external_pixmap(&(K=1), b, a);
}
}
}
//-------------------------------------------------------------------------------------------
void click()
{
int i=m_mouse(z);
int M=z[0],N=z[1];
cout<<M<<endl<<N<<endl;



if(mappa[(max_r-1)-N][M][0]==9)
{
cout<<"Sei esploso schiappa!!\n";
o++;
}
else
{
int K;
char *b;
switch (mappa[(max_r-1)-N][M][0])
{
case 1: b="a.ppm";
break;
case 2: b="b.ppm";
break;
case 3: b="c.ppm";
break;
case 4: b="d.ppm";
break;
case 5: b="e.ppm";
break;
case 6: b="f.ppm";
break;
case 7: b="g.ppm";
break;
case 8: b="h.ppm";
break;
case 9: b="mina.ppm";
break;

z[0]=M, z[1]=N;
int a[]={M*16,(max_r-N)*16,0,0,max_r,max_c,0};
int X=1,Y=1;
m_use_as_pixmap(&X,&Y);
m_load_external_pixmap(&(K=1), b, a);
q++;
}
}
}


//-------------------------------------------------------------------------------------------
int main()
{
s=time(0);
srandom (s);
cout<<"Quante bombe vuoi?"<<endl;
cin>>bomba;
//griglia();
lamappa(mappa);
leggimappa(mappa);
disegnamappa1(mappa);
for (int G=0;;G++)
{
click();
if(o!=0) break;
}
int K=0;
m_wait_for_events (&K);
//cout<<max_c<<endl<<max_r<<endl;

}
 
Old 07-17-2007, 09:24 AM   #4
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Quote:
Originally Posted by teoporta
Hi,
trying to do something in C++ I fount this error: invalid conversion from 'const char*' to 'char'.

I show you the extract of the program with the error.

M=smth, N=smth;
char *numero="0";
switch (mappa[M][max_r-N][0])
{case 1: *numero=" 1"; //error
case 2: *numero=" 2"; //error
case 3: *numero=" 3"; //error
case 4: *numero=" 4"; //error
case 5: *numero=" 5"; //error
case 6: *numero=" 6"; //error
case 7: *numero=" 7"; //error
case 8: *numero=" 8"; //error
}
The first post shows the reason for the error. You are dereferencing a char pointer and trying to assign a char const*. Seeing as you are using C++ the simplest solution is to use std::string, does the compile not give an warning/error for "char *numero="0";"?


From having a glance at your later post I would surmise you are using Visual studio 6 is this correct? if not then you need to change your header files to
Code:
#include<iostream>
#include<ctime>
#include <passe_par_tout.h>
#include<cstdlib>
Note: It is far easier to look at code which is posted in code tags.

Last edited by dmail; 07-17-2007 at 09:27 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
casting a const char into a char MicahCarrick Programming 3 01-12-2007 07:26 PM
Please !!! Help me : invalid conversion from `char*' to `char' cemetery Programming 17 10-05-2006 11:44 AM
invalid conversion from `const char*' to `char*' deepinlife Programming 22 08-05-2006 10:49 AM
If I get invalid conversion from `const char*' to `char' what should I be lookin for? RHLinuxGUY Programming 5 03-12-2006 10:35 PM
invalid conversion from `char' to `const char* bru Programming 6 05-09-2004 03:07 PM


All times are GMT -5. The time now is 05:12 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration