Novice question..

Discussion in 'C Programming' started by herrcho, Aug 10, 2003.

  1. herrcho

    herrcho Guest

    Here is the code..

    #define NAME "MEGATHINK, INC"
    #define ADDRESS "10 Megabuck Plaza"
    #define PLACE "Megapolis, CA 94904"

    int main()
    {
    starbar();
    printf("%s\n",NAME);
    printf("%s\n",ADDRESS);
    printf("%s\n",PLACE);
    starbar();
    }

    #include <stdio.h>
    #define LIMIT 65
    starbar()
    {
    int count;
    for (count=1;count<=LIMIT;count++)
    putchar('*');
    putchar('\n');
    }

    it shows me the following warning message

    implicit declaration of function 'starbar'
    implicit declaration of function 'printf'
    control reaches end of non-void function

    Could anyone explain why this happens.. i'm still having hard time
    learning C

    thanks in advance.
     
    herrcho, Aug 10, 2003
    #1
    1. Advertising

  2. herrcho

    Bigdakine Guest

    >Subject: Novice question..
    >From: "herrcho"
    >Date: 8/9/03 4:52 PM Hawaiian Standard Time
    >Message-id: <bh4c1j$sp6$>
    >
    >Here is the code..
    >
    >#define NAME "MEGATHINK, INC"
    >#define ADDRESS "10 Megabuck Plaza"
    >#define PLACE "Megapolis, CA 94904"
    >
    >int main()
    >{
    > starbar();
    > printf("%s\n",NAME);
    > printf("%s\n",ADDRESS);
    > printf("%s\n",PLACE);
    > starbar();
    >}
    >
    >#include <stdio.h>
    >#define LIMIT 65
    >starbar()
    >{
    > int count;
    > for (count=1;count<=LIMIT;count++)
    > putchar('*');
    > putchar('\n');
    >}
    >
    >it shows me the following warning message
    >
    >implicit declaration of function 'starbar'


    You didin't have a function definition for starbar when the compiler reached
    the declaration. It will assume you meant

    int starbar();

    Which is not what you meant.

    Put the include and function definition for starbar on top.
    >implicit declaration of function 'printf'


    see above.

    >control reaches end of non-void function


    You declare main to return an int. Yet you have no "return" statement in main.
    >
    >Could anyone explain why this happens.. i'm still having hard time
    >learning C
    >


    Well, it wasn't that bad. Just put things in the right order..

    Stuart
     
    Bigdakine, Aug 10, 2003
    #2
    1. Advertising

  3. herrcho

    amanayin Guest

    #include <stdio.h>
    #define LIMIT 30

    #define NAME "MEGATHINK, INC"
    #define ADDRESS "10 Megabuck Plaza"
    #define PLACE "Megapolis, CA 94904"

    int starbar();

    int main()
    {
    starbar();
    printf("%s\n",NAME);
    printf("%s\n",ADDRESS);
    printf("%s\n",PLACE);
    starbar();
    }

    starbar()
    {
    int count;
    for (count=1;count<=LIMIT;count++)
    putchar('*');
    putchar('\n');
    }
     
    amanayin, Aug 10, 2003
    #3
  4. herrcho

    Lew Pitcher Guest

    herrcho wrote:
    > Here is the code..
    >
    > #define NAME "MEGATHINK, INC"
    > #define ADDRESS "10 Megabuck Plaza"
    > #define PLACE "Megapolis, CA 94904"
    >
    > int main()
    > {
    > starbar();
    > printf("%s\n",NAME);
    > printf("%s\n",ADDRESS);
    > printf("%s\n",PLACE);
    > starbar();
    > }
    >
    > #include <stdio.h>
    > #define LIMIT 65
    > starbar()
    > {
    > int count;
    > for (count=1;count<=LIMIT;count++)
    > putchar('*');
    > putchar('\n');
    > }
    >
    > it shows me the following warning message
    >
    > implicit declaration of function 'starbar'


    Because you use starbar() in your main() function /before/ you define it.
    Your definition of starbar() follows, later in your source code.

    > implicit declaration of function 'printf'


    Because you use printf() in your main() function /before/ you define it.
    Your definition of printf() follows; it comes from the
    #include <stdio.h>

    > control reaches end of non-void function


    You do not define starbar() to return any explicit type of value, so (as is the
    C89 standard), it defaults to returning an int ("implicit int" in the standard).
    However, your starbar() function neglects to explicitly return an int value (it
    does not have a return statement that returns an int), so the compiler warns you
    about this nonstandard behaviour.

    >
    > Could anyone explain why this happens.. i'm still having hard time
    > learning C
    >
    > thanks in advance.



    --
    Lew Pitcher

    Master Codewright and JOAT-in-training
    Registered Linux User #112576 (http://counter.li.org/)
    Slackware - Because I know what I'm doing.
     
    Lew Pitcher, Aug 11, 2003
    #4
    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. ra

    VHDL novice question

    ra, Jul 13, 2004, in forum: VHDL
    Replies:
    6
    Views:
    2,934
    Allan Herriman
    Jul 13, 2004
  2. sean
    Replies:
    1
    Views:
    629
    Cowboy \(Gregory A. Beamer\)
    Oct 20, 2003
  3. sean
    Replies:
    0
    Views:
    329
  4. sean
    Replies:
    2
    Views:
    568
    Kevin Spencer
    Dec 2, 2003
  5. sean

    Forms question - Novice

    sean, Feb 2, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    331
    Steve C. Orr [MVP, MCSD]
    Feb 2, 2004
Loading...

Share This Page