Help

S

Singleton

what is wrong with my main fn?



void f(char** p)

{

printf("%s", p[0]);

}



void main()

{

char a[50][50];

strcpy(a[0], "hello");

f(a);

}
 
J

John Harrison

Singleton said:
what is wrong with my main fn?



void f(char** p)

{

printf("%s", p[0]);

}



void main()

{

char a[50][50];

strcpy(a[0], "hello");

f(a);

}

char[50][50] cannot be converted to char**.

You probably thought that because char[50] does convert to char* that
char[50][50] could convert to char** but you were wrong.

The correct rule is that T[N] can convert to T*, so in the case of
char[50][50] T=char[50], therefore char[50][50] converts to char(*)[50]
(i.e. a pointer to an array of 50 chars) not to char** (a pointer to a
pointer to a char).

So rewrite f like this

void f(char (*p)[50])
{
printf("%s", p[0]);
}

and your program will work.

Get a C or C++ book and read the section on declarations. As you've seen
sometimes your intuition will let you down.

john
 
B

BobR

Singleton wrote in message said:
what is wrong with my main fn?

void f(char** p){
printf("%s", p[0]);
}

void main(){
char a[50][50];
strcpy(a[0], "hello");
f(a);
}

You should ask this in an NG for the language you are using.
Hint: in 'C' and 'C++', 'main()' ALWAYS returns an 'int'.
 
J

Jim Beam

Singleton wrote in message said:
what is wrong with my main fn?

void f(char** p){
printf("%s", p[0]);
}

void main(){
char a[50][50];
strcpy(a[0], "hello");
f(a);
}

You should ask this in an NG for the language you are using.
Hint: in 'C' and 'C++', 'main()' ALWAYS returns an 'int'.

In 'English', 'apostrophes' are used to denote the 'possessive'. You
should ONLY post English in an English language newsgroup.

Do you see?
 
B

BobR

Jim Beam wrote in message ...
Singleton wrote in message said:
what is wrong with my main fn?

void f(char** p){
printf("%s", p[0]);
}

void main(){
char a[50][50];
strcpy(a[0], "hello");
f(a);
}

You should ask this in an NG for the language you are using.
Hint: in 'C' and 'C++', 'main()' ALWAYS returns an 'int'.

In 'English', 'apostrophes' are used to denote the 'possessive'. You
should ONLY post English in an English language newsgroup.

Do you see?

'RATS!' You sure know how to spoil a guys fun! '<G>'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,229
Latest member
GloryAngul

Latest Threads

Top