View Single Post
Old 09-13-2014, 10:22 AM   #11
spoon eater
seamonkey's Avatar
Join Date: Oct 2007
Location: the question is where are you?
Posts: 1,616
Default Re: Problem: Functions In C

@hyperme: he does have an EOF (Ok it isn't a file, but still), marker in his array - so he shouldn't be going out of bounds. He is (in theory) guaranteed to hit a -1 at the end of the user inputted data - which is why

That said your method of initializing your array is also a waste of memory - why reserve 102 slots if you don't need them? Instead initialize the array to have MAX elements, where you define MAX to be the user inputted number. (currently you set the user input to days_in_m)

I said last night that a while loop would be a better loop. This is because in general the condition to run the loop should be related to the updater and the initial variable, which yours is not. For example

while(table[tableindex] != -1)
//Do stuff

One possible bug is that Hyperme is correct, and your loop is escaping your -1. I don't see exactly how this happens, but I do know a way to test it. When you initialize an int[] it fills it by default with 0's. If you have an array that is partially filled and it escapes past your -1 marker, it will default back to a zero. An easy way to test whether this is the case is to fill the array with a bunch of 999's at the start, and then run the program again and look at the max result.
French fry Kremlin the morose nucleotides!-Jamul
There is no fifth amendment in mafia games - you don't have a right to be silent!- hammered
"So tell me Harry, what exactly is the purpose of a rubber duck?" -Mr. Weasly

Last edited by seamonkey; 09-13-2014 at 01:56 PM.
seamonkey is offline   Reply With Quote