Help

Discussion in 'C++' started by Singleton, Nov 25, 2005.

  1. Singleton

    Singleton Guest

    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);

    }
     
    Singleton, Nov 25, 2005
    #1
    1. Advertising

  2. 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
     
    John Harrison, Nov 25, 2005
    #2
    1. Advertising

  3. Singleton

    BobR Guest

    Singleton wrote in message <43874a93$>...
    >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
     
    BobR, Nov 25, 2005
    #3
  4. Singleton

    Jim Beam Guest

    On Fri, 25 Nov 2005 23:20:10 GMT, "BobR"
    <> wrote:

    >
    >Singleton wrote in message <43874a93$>...
    >>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?
     
    Jim Beam, Nov 25, 2005
    #4
  5. Singleton

    BobR Guest

    Jim Beam wrote in message ...
    >On Fri, 25 Nov 2005 23:20:10 GMT, "BobR"
    ><> wrote:
    >
    >>Singleton wrote in message <43874a93$>...
    >>>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
     
    BobR, Nov 26, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?dHJlbGxvdzQyMg==?=

    HELP! HELP! HELP! Opening Web Application Project Error

    =?Utf-8?B?dHJlbGxvdzQyMg==?=, Feb 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    792
    =?Utf-8?B?dHJlbGxvdzQyMg==?=
    Feb 20, 2004
  2. Harvey
    Replies:
    0
    Views:
    750
    Harvey
    Jul 16, 2004
  3. Harvey
    Replies:
    1
    Views:
    880
    Daniel
    Jul 16, 2004
  4. =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?=

    HELP - HELP - HELP

    =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?=, Mar 9, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    703
    Eliyahu Goldin
    Mar 9, 2006
  5. Buster

    Help, Help, Help

    Buster, Oct 4, 2003, in forum: Java
    Replies:
    3
    Views:
    484
    Saager
    Oct 30, 2003
Loading...

Share This Page