Novice question..

H

herrcho

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.
 
B

Bigdakine

Subject: Novice question..
From: "herrcho" (e-mail address removed)
Date: 8/9/03 4:52 PM Hawaiian Standard Time
Message-id: <[email protected]>

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
 
A

amanayin

#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');
}
 
L

Lew Pitcher

herrcho said:
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 said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top