Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Help

Reply
 
 
Singleton
Guest
Posts: n/a
 
      11-25-2005
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);

}



 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      11-25-2005
Singleton wrote:
> 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
 
Reply With Quote
 
 
 
 
BobR
Guest
Posts: n/a
 
      11-25-2005

Singleton wrote in message <43874a93$(E-Mail Removed)>...
>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'.

--
Bob R
POVrookie


 
Reply With Quote
 
Jim Beam
Guest
Posts: n/a
 
      11-25-2005
On Fri, 25 Nov 2005 23:20:10 GMT, "BobR"
<(E-Mail Removed)> wrote:

>
>Singleton wrote in message <43874a93$(E-Mail Removed)>...
>>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?
 
Reply With Quote
 
BobR
Guest
Posts: n/a
 
      11-26-2005

Jim Beam wrote in message ...
>On Fri, 25 Nov 2005 23:20:10 GMT, "BobR"
><(E-Mail Removed)> wrote:
>
>>Singleton wrote in message <43874a93$(E-Mail Removed)>...
>>>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>'

--
Bob R
POVrookie


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Help Help Pentax S5i Help needed (Please) The Martian Digital Photography 14 06-20-2008 07:56 AM
HELP - HELP - HELP =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?= ASP .Net 4 03-09-2006 12:46 PM
HELP WANTED HELP WANTED HELP WANTED Harvey ASP .Net 1 07-16-2004 01:12 PM
HELP WANTED HELP WANTED HELP WANTED Harvey ASP .Net 0 07-16-2004 10:00 AM
HELP! HELP! HELP! Opening Web Application Project Error =?Utf-8?B?dHJlbGxvdzQyMg==?= ASP .Net 0 02-20-2004 05:16 PM



Advertisments