mathmari
Gold Member
MHB
- 4,984
- 7
I like Serena said:We account for it inside the function yes.
But when it fails, we have $k=-1$.
Then, in the main() function the StarS[] array still gets indexed with $k=-1$, which will result in a bit of madness and chaos. (Worried)
So, we could write the following if in the main() function, after calling the function, instead of writing it in the function Beginning, right?? (Wondering)
Code:
if(k==-1){
printf("The star system with identifier %d couldn't be found\n", ss);
}
I like Serena said:Btw, it is bad programming style to keep the $k$ outside the function in the global namespace. It is better to declare it inside the function, and when you call the function keep track of the value that the function returned. (Nerd)
Ok, I changed it! (Yes)
Now it works! (Happy)