View previous topic :: View next topic |
Author |
Message |
Little-Acorn
Joined: 06 Jul 2008 Posts: 111 Location: San Diego
|
Posted: Tue Nov 27, 2012 5:42 am Post subject: Printing from inside a function with SCC? |
|
|
I drew a simple function, intended to print out a single line (with several carriage-returns). But for some reason it doesn't.
First the main program should print out a carriage return followed by "Hello, world! Value =" followed by an integer value, then a couple carriage returns. Then it should print "Function writstat has been entered" with a couple more carriage returns, and then a single integer value.
I expected to get a garbage value (actually a pointer value) back, and I did. No surprise there.
But why it doesn't print out "Function writstat has been entered" with the carriage-returns?
---------------------------------------------
#include "stdio.h"
int writstat()
{
int i;
i=13;
printf("\nFunction writstat has been entered.\n\n");
return(i);
}
main()
{
printf("Hello, world! Value = %d\n\n",writstat);
}
--------------------------------------------------- |
|
Back to top |
|
 |
jalih
Joined: 30 Jul 2012 Posts: 196
|
Posted: Tue Nov 27, 2012 7:03 am Post subject: Re: Printing from inside a function with SCC? |
|
|
Little-Acorn wrote: |
But why it doesn't print out "Function writstat has been entered" with the carriage-returns?
|
It's simply because you never call the function writstat in your code, you are missing () after the function name.
There are other errors in your code:
- standard headers should be included as:
- main function should return a integer value. Old compiler assumes this and let's your code compile without nagging, but it's still a good habit. |
|
Back to top |
|
 |
Little-Acorn
Joined: 06 Jul 2008 Posts: 111 Location: San Diego
|
Posted: Tue Nov 27, 2012 7:16 am Post subject: Re: Printing from inside a function with SCC? |
|
|
jalih wrote: |
Little-Acorn wrote: |
But why it doesn't print out "Function writstat has been entered" with the carriage-returns?
|
It's simply because you never call the function writstat in your code, you are missing () after the function name. |
That was it! Thank you!
Quote: |
There are other errors in your code:
- standard headers should be included as:
- main function should return a integer value. Old compiler assumes this and let's your code compile without nagging, but it's still a good habit. |
I have now corrected my code to include these. Thanks for your help! |
|
Back to top |
|
 |
|