So I'm trying to print out an array that I'm returning from a function. Right now only the first element in the array comes back correctly, the rest of them contain junk. What am I doing wrong?
Your function menu() is invalid since it returns a pointer to a local variable which is destroyed after the function exits. Either pass a valid pointer with enough space into the function or use dynamic allocation.
I was really confused by your answer (apparently I'm really bad at this stuff) but I played around with it based on what you said and it looks like I figured it out! Thanks a bunch! Here's the solution in case it helps anyone in the future:
Well, I understand that arrays (any variable) created inside a function will be destroyed when the function is finished, and what I was doing before was passing back a pointer of the array, which is the first element in the array but when the compiler tried to print the other elements they were already destroyed so I got junk.
Now what I'm doing is creating a dynamic array and the values are put inside the new array at compile time... Actually no I don't understand that at all.
I also don't understand why when I generate multiple tickets all the values are the same..
Update- fixed the random number issue by taking the seed(er) out of the function and putting it in the main.