(Being fairly new at C++) I'm having an issue with a program I'm writing. It has successfully been compiled and ran fine yesterday.
However when I opened it today it crashed.
I debugged it and I'm getting popup window saying "An Access Violation (Segmentation Fault) raised in your program."
I've been double checking everything for a while and I can't find anything I did wrong.
I haven't written all of the code yet, I'm dividing it into function, but leaving the cases empty shouldn't give me any issues.
So far the error only occurs for case MANUALLY and case FROM_FILE in the second switch menu. Case DISPLAY_CHART works just fine.
The variable priceRow is an uninitialized pointer. And it remains uninitialized throughout the whole program as far as i can see it. Accessing this uninitialized pointer will lead to undefined behavior. Usually a crash.
Because you always use the constants MAX_ROWS and MAX_SEATS the arrays must have exact this amount of valid data. Everything else is an error. I don't think that you want this behavior?
Standard recommendation: Step through your code in a debugger. That will show you exactly where your code is crashing, and allow you to examine the state of the memory at that point to see why it's crashing.
Thank you, I have tried, and I'm still trying to work with priceRow. I defined it as double *priceRow because i want this blank array to go in function rowPrices() where it will be filled by the user and then I want to return it to main so that it can be read from there. When I define double priceRow[MAX_ROWS] then i have a conversion problem with my function priceRow. I want to return an array[15] to main but i can't put double[15] in front of rowPrices(): double[15] rowPrices() {}.
I am somewhat new to arrays and I'm quite confused as to how to make this one work quite frankly.
@Mikey Boy
Thank you, I've indeed been doing that however my debugging 'skills' are somewhat limited so far. I do think that what has been pointed out above must be what's crashing my program.
Well I solved it, actually what wasn't working was priceRow = rowPrices(priceRow).
I figured you can't return the array priceRow if it is also the argument of the function rowPrices() in: priceRow = rowPrices(priceRow).
So I created double price[MAX_ROWS] and used it like so: priceRow = rowPrices(price); and now it works.
Thank you a lot for your time anyway, sorry for bothering.
There is no reason for rowPrices(...) and readRowPrices (...) to return the pointer passed in. The array passed in will be modified. The return value does not have any relevance. Thus priceRow should be an array not a pointer.