Java is derived from C. You can use dynamic memory allocation.
Majestics
Practically a Master Poster
621 posts since Jul 2007
Reputation Points: 199
Solved Threads: 49
How is frameScores declared?
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
>>int temp[sizeof(frameScores)+1];
That line is wrong. If frameScores is declared as int frameScores[5] then the above declaration will create an array of 5*sizeof(int) = 20+1 elements. What you want is 6 elements, so the line should be int temp[sizeof((frameScores)/sizeof(frameScores[0]))+1];
Well that will correct that line, but it still will not correct the line frameScores = temp; because the two arrays are not the same size.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
If you are attempting to add a new element to frameScores array, such as increase its size from 5 to 6 elements, then make frameScores a pointer and reallocate its size.
int* frameScores= {0};
int frameSize = 0; // size of frameScores
int totalScore = 0;
int lastFrameNumber = 0;
void addFrame(int toAdd)
{
totalScore = totalScore + toAdd;
if (frameSize < lastFrameNumber)
{
frameScores = (int *)realloc(frameScores,(frameSize+1) * sizeof(int));
frameScores[frameSize] = totalScore;
++frameSize;
}
}
int main()
{
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343