PLEASE NOTE: the upgrades to this server, secure.csse.uwa.edu.au, have not yet been completed.
Hopefully the changes will be completed on THURSDAY 8th December.
Web-based programs, such as csmarks, cssubmit, and the help fora, will be unavailable at some time on Thursday 8th.
  It's UWAweek 49

help2002

This forum is provided to promote discussion amongst students enrolled in CITS2002 Systems Programming.
Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.

Displaying the 7 articles in this topic
Showing 7 of 919 articles.
Currently 2 other people reading this forum.


 UWA week 36 (2nd semester, mid-semester break) ↓
SVG not supported

Login to reply

👍?
helpful
2:17pm Wed 7th Sep, ANONYMOUS

To return the top command, should the function's header be 'char my_function()' or 'const char *' (suggested by Google)? The compiler returns "address of stack memory associated with local variable 'command' returned..." when returning "m" for testing. Cheers.


SVG not supported

Login to reply

👍?
helpful
3:29pm Wed 7th Sep, Christopher M.

ANONYMOUS wrote:
> To return the top command, should the function's header be 'char my_function()' or 'const char *' (suggested by Google)? The compiler returns "address of stack memory associated with local variable 'command' returned..." when returning "m" for testing. Cheers.
This question has no context. What is "the top command" ? What function? When you say "header", do you mean "prototype" or "declaration" ?


SVG not supported

Login to reply

👍?
helpful
8:38pm Wed 7th Sep, ANONYMOUS

"Christopher McDonald" <ch*i*.*c*o*a*[email protected]*a*e*u*a*> wrote:
> ANONYMOUS wrote: > > > To return the top command, should the function's header be 'char my_function()' or 'const char *' (suggested by Google)? The compiler returns "address of stack memory associated with local variable 'command' returned..." when returning "m" for testing. Cheers. > > This question has no context. > What is "the top command" ? > What function? > When you say "header", do you mean "prototype" or "declaration" ?
Hi, yes thanks for the clarification. The top command is one of the values, which could be a sequence of characters, that we should be returning for Project 1 2022. If we were to create a function to return this value, what would the function declaration look like? Would it be 'char my_function()' or 'const char *'to return a sequence of characters for the top command of Project 1?


SVG not supported

Login to reply

👍?
helpful
1:29am Thu 8th Sep, ANONYMOUS

ANONYMOUS wrote:
> "Christopher McDonald" <ch*i*.*c*o*a*[email protected]*a*e*u*a*> wrote: > > > ANONYMOUS wrote: > > > > > To return the top command, should the function's header be 'char my_function()' or 'const char *' (suggested by Google)? The compiler returns "address of stack memory associated with local variable 'command' returned..." when returning "m" for testing. Cheers. > > > > This question has no context. > > What is "the top command" ? > > What function? > > When you say "header", do you mean "prototype" or "declaration" ? > > > Hi, yes thanks for the clarification. The top command is one of the values, which could be a sequence of characters, that we should be returning for Project 1 2022. If we were to create a function to return this value, what would the function declaration look like? Would it be 'char my_function()' or 'const char *'to return a sequence of characters for the top command of Project 1?
Oh, I've managed to return the string by declaring a pointer for the value of variable 'command': char *command = "m". Cheers for your time.


SVG not supported

Login to reply

👍x1
helpful
3:47am Thu 8th Sep, Christopher M.

ANONYMOUS wrote:
> Hi, yes thanks for the clarification. The top command is one of the values, which could be a sequence of characters, that we should be returning for Project 1 2022. If we were to create a function to return this value, what would the function declaration look like? Would it be 'char my_function()' or 'const char *'to return a sequence of characters for the top command of Project 1?
Glad that you've now solved this, but it should have been an easy one to work out: - char my_function(...) returns just a single character - char *my_function(...) returns a pointer to a character, which we assume to be the beginning of a string of characters.


SVG not supported

Login to reply

👍?
helpful
11:40am Thu 8th Sep, ANONYMOUS

Can we have a printf statement and a return statement in one function? I want to debug my code by ensuring that the values I'm retrieving from my data structure are what I want (using printf()). But if I have a return statement and call printf, nothing gets printed.


SVG not supported

Login to reply

👍x1
helpful
2:56pm Thu 8th Sep, Christopher M.

Yes (of course), you may have any number of calls to printf() and any number of return statements in a single function. Whenever tempted to ask such a question, test things yourself by writing a small, stand-alone, program, independent of your project, and see what you can learn from it.

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  1:17AM Sep 14 2022
Privacy policy