#Help with main function not exiting when another function has return 0;
30 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
am I doing something wrong?
You need to check the return value when you call the Choices function
Make sure to return a value from all paths in your Choices function as well
Also please don’t tell me you did
#define ZERO 0
#define ONE 1
#define FORTYFIVETHOUSAND 45000```
Yeah. had to cause that's what my prof wants
Why??
You can
- A) call
exitfrom yourchoicesfunction or - B) store the return value of
choicesand proceed based on that
Btw: Your choices function as of right now isn't complete because it only returns something in the default case, but nothing in any other case. Are you compiling with -Wall -Wextra?
Also:
!sc
They're hard to read and prevent copying and pasting.
!code
```c
int main() {}
```
int main() {}
Could I just send the c file instead?
yup
Had them in seperate files (cause prof)
the cases do return the print functions but I'm not able to exit when using the default case
ignore if this isn't the most optimal way to do things still learning
They don't "return the print functions".
That doesn't make sense as a sentence.
The print functions just produce a side effect of printing text to the screen. After the print your code runs into the break which jumps past the switch-case but there is no return ... anywhere to be seen (other than the default case).
Are you compiling with warnings enabled? If not then change that. As I said the warning flags are -Wall and -Wextra. Also compile with -Werror so that warnings are being treated as errors and your code doesn't even compile in these cases.
Next issue is that you're not actually storing the return value of the Choices function, but just calling it like you would call any void function like printbinary or BitCheck when it in fact should return an integer that you should store and based on that return value you can then determine whether the function was successful or not (e.g. a return value of 0 would mean unsuccessful while a return value of 1 would mean successful but that's up for you to choose).
I wasn't compiling with -Wall. didn't even know that was a thing. I'll be sure to do that and I'm understanding what you're saying now about the return
my bad about the "return print function" 😭 thought you meant like if it does anything. I'll work on this
I'll work on this after a short break 😔 been doing it since the morning
all good, you do you.
I don't care when or if you do it. That's your bread and butter.
Just thought it was funny
Thanks for the help tho. Learned something new about compiling
@prisma grove Has your question been resolved? If so, type !solved :)