0

i have to convert a program from c++ to C language and at one point in my program im stuck where its dealing with dynamic memory of an array. i started it but i dont know how u do dynamic memomory in c language.

if (reply == '1')
   {
      printf("Enter the 1st score (any invalid score to quit): ");
      scanf("%d", score);
      while (score >= 0 && score <= 100)
      {
         ++numOfScores;
         if (numOfScores > arraySize)
         {
            arraySize = int(1.5*arraySize + 1);
            scoresArrayPtrHold = scoresArrayPtr;
            scoresArrayPtr = new int [arraySize];
            for (int i = 0; i < numOfScores - 1; ++i)
               *(scoresArrayPtr + i) = *(scoresArrayPtrHold + i);
            free(scoresArrayPtrHold);
            scoresArrayPtrHold = 0;
         }
         *(scoresArrayPtr + numOfScores - 1) = score;

         printf("Enter the next score (any invalid score to end): ");
         scanf("%d", score);
      }
6
Contributors
7
Replies
8
Views
12 Years
Discussion Span
Last Post by dwks
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.