Silverfrost Forums

Welcome to our forums

Printing from inside a function with SCC?

27 Nov 2012 4:42 #11198

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); }


27 Nov 2012 6:03 #11199

Quoted from Little-Acorn

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: #include<stdio.h>

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

27 Nov 2012 6:16 #11200

Quoted from jalih

Quoted from Little-Acorn

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!

There are other errors in your code:

  • standard headers should be included as: #include<stdio.h>

  • 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!

Please login to reply.