0

I am using MS VC++ '08, ad have run into a problem that stumps me :

void printtext(char **lotsoftext,int m,int n)
{
for(int i=0;i<n;i++)
  for(int j=0;j<m;j++)
    print(lotsoftext[i][j]);
}

The error is as follows :
cannot convert parameter 1 from 'char' to 'const char *'

How do i correctly refer to lotsoftext ?
Oh, and i don't want to use 2d arrays, so please don't tell me to do that. ;)

2
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by firstPerson
0

short answer : change

void printtext(char **lotsoftext,int m,int n)

to

void printtext(const char **lotsoftext,int m,int n)

Just a side note, when your function does not change the content of its arguments thats passed, then make
them const.

0

Thanks, that stopped the compilation errors atleast.

But suppose if i make a similar function that does change the array, how would I go about doing that?

For example,

void printtext(char **lotsoftext,int m,int n)
{
for(int i=0;i<n;i++)
  for(int j=0;j<m;j++)
    {
           print(lotsoftext[i][j]);
           if(i==2 && j==1)
              lotsoftext[i][j] = "Hello";
}
0

if it changes its values then your functions should have
a non const array as a parameter like so :

void printtext(char **lotsoftext,int m,int n)

but you cannot pass a const array to it because the function
does not promise not to change its content.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.