By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,218 Members | 1,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,218 IT Pros & Developers. It's quick & easy.

Novice question..

P: n/a
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.
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
>Subject: Novice question..
From: "herrcho" he*********@kornet.net
Date: 8/9/03 4:52 PM Hawaiian Standard Time
Message-id: <bh**********@news1.kornet.net>

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
Nov 13 '05 #2

P: n/a
#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');
}
Nov 13 '05 #3

P: n/a
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.

Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.