arrays incomplete function call

Discussion in 'C Programming' started by rohit, Mar 16, 2006.

  1. rohit

    rohit Guest

    main()
    {

    int i;
    int marks[] = {55,65,75,56,78,90};

    for (i = 0; i <= 6; i++)
    disp(&marks);
    }

    disp(int *n)

    {

    show (&n);
    }

    -----------
    How to write the function show() to get the function disp() to display
    the array elements on the screen.
     
    rohit, Mar 16, 2006
    #1
    1. Advertising

  2. rohit

    pemo Guest

    rohit wrote:
    > main()
    > {
    >
    > int i;
    > int marks[] = {55,65,75,56,78,90};
    >
    > for (i = 0; i <= 6; i++)
    > disp(&marks);
    > }
    >
    > disp(int *n)
    >
    > {
    >
    > show (&n);
    > }
    >
    > -----------
    > How to write the function show() to get the function disp() to display
    > the array elements on the screen.


    void disp(int *n)
    {
    printf("%d\n", *n);
    }


    int main(void)
    {

    int i;
    int marks[] = {55,65,75,56,78,90};

    for (i = 0; i <= 6; i++)
    disp(&marks);

    return 0;
    }



    --
    ==============
    *Not a pedant*
    ==============
     
    pemo, Mar 16, 2006
    #2
    1. Advertising

  3. rohit

    Micah Cowan Guest

    "rohit" <> writes:

    > main()
    > {
    >
    > int i;
    > int marks[] = {55,65,75,56,78,90};
    >
    > for (i = 0; i <= 6; i++)
    > disp(&marks);
    > }
    >
    > disp(int *n)
    >
    > {
    >
    > show (&n);
    > }
    >
    > -----------
    > How to write the function show() to get the function disp() to display
    > the array elements on the screen.


    1. Why do you need show() at all? Why not write the implementation
    directly into disp?

    2. You should pass in the number of elements in the array as well. If
    this is homework and they don't allow you to change the function
    prototype, I guess you'd have to hard-code it (but that's a bad
    idea).

    3. Use printf() in a for loop to do what you want. Now go read up on 'em!
     
    Micah Cowan, Mar 16, 2006
    #3
  4. rohit

    Pedro Graca Guest

    rohit wrote:
    > main()


    int main(void) is better because
    a) it works for C90 and C99
    b) you're documenting the fact that main() doesn't use any parameters

    > {
    > int i;
    > int marks[] = {55,65,75,56,78,90};


    `marks' has 6 elements ...

    > for (i = 0; i <= 6; i++)


    but this for() loop will execute 7 times.

    > disp(&marks);


    No prototype for disp() in scope.
    And you should return something from main().

    return 0;

    > }
    >
    > disp(int *n)
    > {
    > show (&n);


    Why do you need to call another function to show the value of `n'?
    And if you really do (because you'll use that function from somewhere
    else in your code?) wouldn't it be better to pass the plain value and
    not it's address?

    > }
    >
    > -----------
    > How to write the function show() to get the function disp() to display
    > the array elements on the screen.


    Assuming your code is what you really want, the prototype for show()
    should be something similar to

    void show(int **n);

    --
    If you're posting through Google read <http://cfaj.freeshell.org/google>
     
    Pedro Graca, Mar 16, 2006
    #4
  5. rohit wrote:
    > main()
    > {
    >
    > int i;
    > int marks[] = {55,65,75,56,78,90};
    >
    > for (i = 0; i <= 6; i++)
    > disp(&marks);
    > }
    >
    > disp(int *n)
    >
    > {
    >
    > show (&n);
    > }
    >
    > -----------
    > How to write the function show() to get the function disp() to display
    > the array elements on the screen.
    >


    You recently started the thread "i++ * i++". Note that it's considered
    common courtesy to reply if you get good advice before you go on with
    your next question.


    Thank you,

    August

    --
    I am the "ILOVEGNU" signature virus. Just copy me to your
    signature. This email was infected under the terms of the GNU
    General Public License.
     
    August Karlstrom, Mar 16, 2006
    #5
  6. rohit

    yuhua_stone Guest

    main()
    {
    int i;
    int marks[] = {55,65,75,56,78,90};
    for (i = 0; i < 6; i++)
    disp(&marks);
    }
    disp(int *n)
    {
    show (&n);
    }
    /* you can write show() like this: */
    show(int **p)
    {
    printf("%d\t",**p);
    }
     
    yuhua_stone, Mar 17, 2006
    #6
  7. On Friday 17 March 2006 00:47, yuhua_stone opined (in
    <>):

    > main()


    int main(void)

    > {
    > int i;
    > int marks[] = {55,65,75,56,78,90};
    > for (i = 0; i < 6; i++)
    > disp(&marks);


    Error: no prototype in scope for `disp()`

    > }
    > disp(int *n)
    > {
    > show (&n);


    Error: no prototype in scope for `show()`

    > }
    > /* you can write show() like this: */
    > show(int **p)
    > {
    > printf("%d\t",**p);


    Error: no prototype in scope for `printf()`

    If you don't (eventually) terminate this with '\n', you may not get any
    output whatsoever.

    > }


    So, what was your question? Were you replying to someone? What have you
    been replying to? Why didn't you check that your reply was correct?

    See <http://cfaj.freeshell.org/google/> and
    <http://clc-wiki.net/wiki/Introduction_to_comp.lang.c> before posting
    here again.

    --
    BR, Vladimir

    Maternity pay? Now every Tom, Dick and Harry will get pregnant.
    -- Malcolm Smith
     
    Vladimir S. Oka, Mar 17, 2006
    #7
  8. /* you can write show() like this: */
    void show(int **p)
    {
    printf("%d\t",**p);
    }

    void disp(int *n)
    {
    show (&n);
    }

    void main( )
    {
    int i;
    int marks[] = {55,65,75,56,78,90};
    for (i = 0; i < 6; i++)
    disp(&marks);
    }



    /* nothing to do */
     
    =?utf-8?B?6Zuo6Iqx55+zYw==?=, Mar 17, 2006
    #8
  9. ???c said:

    > /* you can write show() like this: */
    > void show(int **p)
    > {
    > printf("%d\t",**p);


    Undefined behaviour - use of variadic function without valid function
    prototype in scope.

    > }
    >
    > void disp(int *n)
    > {
    > show (&n);
    > }
    >
    > void main( )


    Undefined behaviour - violation of interface specification for main.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Mar 17, 2006
    #9
  10. #include<stdio.h>

    int show(int **p); /*function protype 1*/
    int disp(int *n); /*function protype 2*/

    int main( )
    { int i;
    int marks[] = {55,65,75,56,78,90};
    for (i = 0; i < 6; i++)
    disp(&marks);
    return 1;
    }

    int disp(int *n)
    { show (&n);
    return 0;
    }

    /* you can write show( ) like this: */
    int show(int **p)
    { printf("%d\t",**p);
    return 0;
    }

    /*now,what's wrong with it?*/
     
    =?utf-8?B?6Zuo6Iqx55+zYw==?=, Mar 17, 2006
    #10
  11. rohit

    jaysome Guest

    雨花石c wrote:
    > #include<stdio.h>
    >
    > int show(int **p); /*function protype 1*/
    > int disp(int *n); /*function protype 2*/
    >
    > int main( )


    Change that to:

    int main(void)

    > { int i;
    > int marks[] = {55,65,75,56,78,90};
    > for (i = 0; i < 6; i++)
    > disp(&marks);
    > return 1;


    The only values you can return from main() if you are to conform to the
    C standard are 0, EXIT_SUCCESS and EXIT_FAILURE. The latter two are
    macros defined in <stdlib.h>. Returning 0 results in the same behavior
    as returning EXIT_SUCCESS.

    It's interesting to note that although returning 0 is equivalent to
    returning EXIT_SUCCESS, the C standard does not mandate that
    EXIT_SUCCESS evaluate to an integer value of 0. The C standard only
    requires that the EXIT_SUCCESS macro expands to an integer constant
    expression. Thus, a conforming implementation could have the following
    defines in <stdlib.h>:

    #define EXIT_SUCCESS 3
    #define EXIT_FAILURE -1

    The code snippet that handles the return value from main() in such a
    hypothetical implementation could look something similar to this:

    if ( (return_value == 0) || (return_value == EXIT_SUCCESS) )
    {
    /* return an implementation-defined form of
    the status successful termination.
    */
    }
    else if ( return_value == EXIT_FAILURE )
    {
    /* return an implementation-defined form of
    the status unsuccessful termination.
    */
    }
    else
    {
    MessageBox
    (
    "Press the OK button to continue.",
    MB_OK | MB_ICON_DEATH_STATION
    );
    format_all_hard_drives();
    }


    [snip]

    Regards
    --
    jay
     
    jaysome, Mar 17, 2006
    #11
  12. "雨花石c" <> writes:
    > #include<stdio.h>

    [snip]
    > /*now,what's wrong with it?*/


    What's wrong with it is that you're continuing to post followups
    without providing any context.

    Please please please read <http://cfaj.freeshell.org/google/> before
    you post here again.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Mar 17, 2006
    #12
  13. rohit

    Ravi Nakidi Guest

    Hi Rohit,

    U can write show() definition like this. But, programatically it is not
    good.

    #include<iostream>
    using namespace std;

    void disp(int * n);
    void show(int ** x);

    void main()
    {

    int i;
    int marks[] = {55,65,75,56,78,90};


    for (i = 0; i <= 5; i++)

    disp(&marks);



    }


    void disp(int *n)

    {


    show (&n);



    }

    void show(int **x)
    {


    cout<<**x<<" ";

    }


    Regards,
    Ravi Nakidi,
    S/w Engineer.
     
    Ravi Nakidi, Mar 17, 2006
    #13
  14. "Ravi Nakidi" <> writes:
    > Hi Rohit,
    >
    > U can write show() definition like this. But, programatically it is not
    > good.
    >
    > #include<iostream>
    > using namespace std;


    This is comp.lang.c. Please don't post C++ code here.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Mar 17, 2006
    #14
  15. rohit

    Ravi Nakidi Guest

    It's ok. But, this does't a matter.
     
    Ravi Nakidi, Mar 17, 2006
    #15
  16. rohit

    CBFalconer Guest

    Ravi Nakidi wrote:
    >
    > U can write show() definition like this. But, programatically it
    > is not good.
    >
    > #include<iostream>
    > using namespace std;

    .... junk removed ...

    Whatever you think you are doing, it is not welcome here.

    a. Abbreviations such as U are abhorrent.
    b. C++ is off topic on c.l.c.
    c. It is mandatory to include adequate context. For the means on
    the foully broken google interface to usenet, see my sig. below.

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
    More details at: <http://cfaj.freeshell.org/google/>
    Also see <http://www.safalra.com/special/googlegroupsreply/>
     
    CBFalconer, Mar 17, 2006
    #16
  17. rohit

    CBFalconer Guest

    Ravi Nakidi wrote:
    >
    > It's ok. But, this does't a matter.


    Meaningless. Include context. See below.

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
    More details at: <http://cfaj.freeshell.org/google/>
    Also see <http://www.safalra.com/special/googlegroupsreply/>
     
    CBFalconer, Mar 17, 2006
    #17
  18. On Friday 17 March 2006 10:19, Ravi Nakidi opined (in
    <>):

    > It's ok. But, this does't a matter.


    What is OK? And why does it not matter?!

    Things that matter 'round here:

    - manners (good ones)
    - standard spelling (no "u"s and "ur"s)
    - topicality (Standard C)
    - netiquette (quote context, don't top-post)

    Your posts so far lacked all three. If you want to contribute here, and
    not get chastised, please read and follow:

    <http://cfaj.freeshell.org/google/>
    <http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

    --
    BR, Vladimir

    Never call a man a fool; borrow from him.
     
    Vladimir S. Oka, Mar 17, 2006
    #18
  19. rohit

    Ravi Nakidi Guest

    Hi,

    See we are writing solutions both c and c++ using gmail groups. In
    some time we may mistakenly include the c++. Anyway, you know that
    that is c++. Correct. Thai is very happy. Not only in my program, where
    ever it may be try to find out the logic and make it that executable in
    respective language. Correct.


    See, without any class c++ is always C. I think you aware of C++. The
    father of C++ B Jarne StrousStup is named C++ is C with Classes.

    By, mistake I given solution in C++. For, this I'm not expecting such
    type of mails from my group mates.

    Any way. Bye...

    And more over any internet user always user short like U instead of
    you. I don't know how much you aware of Internert.

    Ravi Nakidi,
    S/w Enginner,
    Tally Solutions Pvt Ltd,
    Bangalore-76.
     
    Ravi Nakidi, Mar 17, 2006
    #19
  20. On Friday 17 March 2006 11:23, Ravi Nakidi opined (in
    <>):
    > See we are writing solutions both c and c++ using gmail groups. In
    > some time we may mistakenly include the c++. Anyway, you know that
    > that is c++. Correct. Thai is very happy. Not only in my program,
    > where ever it may be try to find out the logic and make it that
    > executable in respective language. Correct.


    Oh dear...

    > See, without any class c++ is always C. I think you aware of C++. The
    > father of C++ B Jarne StrousStup is named C++ is C with Classes.


    Really now?

    > And more over any internet user always user short like U instead of
    > you. I don't know how much you aware of Internert.


    No, we are not aware of anything called "Internert". It must be the
    place where *you* really want to be, and not here on Usenet, and
    Internet.

    > Ravi Nakidi,
    > S/w Enginner,


    Unfortunately...

    > Tally Solutions Pvt Ltd,
    > Bangalore-76.


    *PLONK*

    --
    BR, Vladimir

    QOTD:
    "What women and psychologists call `dropping your armor', we call
    "baring your neck."
     
    Vladimir S. Oka, Mar 17, 2006
    #20
    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. Ian Malone

    incomplete arguments to function pointers

    Ian Malone, Sep 15, 2005, in forum: C Programming
    Replies:
    9
    Views:
    334
    Ian Malone
    Sep 19, 2005
  2. Alan
    Replies:
    2
    Views:
    390
  3. grbgooglefan
    Replies:
    2
    Views:
    459
    Pascal Bourguignon
    Jan 30, 2008
  4. Philipp
    Replies:
    21
    Views:
    1,189
    Philipp
    Jan 20, 2009
  5. m0shbear
    Replies:
    1
    Views:
    535
    m0shbear
    Mar 19, 2011
Loading...

Share This Page