Is there a memory leak in this code?

Posted on 2005-04-15
Last Modified: 2010-04-15
Can someone point me in the right direction and tell me what is wrong here? I keep getting a funny paragraph symbol at the end of my output...

#include <stdio.h>
#include <system.h>
#include <stdlib.h>

char DisplayTitle(void);
void GetNumbers(int *parrNumb);
int FindMax(int *parrNumb);
int FindMin(int *parrNumb);
void DisplayNumbers(int min, int max);

int main(void)
  char quitNow='a';   /* to determine if uer wants to quit */
  int min=0;       /* minimum number in array */
  int max=0;       /* maximum number in array */
  int arrNumb[10]; /* user input into array   */
  int *parrNumb;   /* pointer to array */
  int i=0;         /* used as a counter in array */
  for (i=0; i<10; i++) /* initialize array to 0's */
      arrNumb[i] = 0;
  //display the title of the program
  quitNow = DisplayTitle();
  if (quitNow=='Q' || quitNow=='q')
     return 0;
  //Get all 10 numbers from user
  //Find minimum number in array
  min = FindMin(arrNumb[10]);
  //Find maximum number in array
  max = FindMax(arrNumb[10]);  
  //display the output
  DisplayNumbers(min, max);
  printf("\nPress any key to end.");
  return 0;

/* DisplayTitle Function
   Input  : Non
   Process: Displays Title and Instructions
   Output : None
char DisplayTitle(void)
    char quitNow; /* does user want to exit program */

    printf("Array Program\n");
    printf("Application will ask for 10 numbers and then return the largest\nand smallest numbers.\n");
    printf("Enter (Q) to Quit Application or press any other key to continue.\n");
    return quitNow;

/* GetNumbers Function
   Input  : Array of integers
   Process: Get user's input (up to 10 times)
   Output : None. Values returned through pointer
void GetNumbers(int *parrNumb)
    int getnumb=0;    /* user choice from menu passed to main */
    int count;  /* used to determine when 10 numbers added */

        printf("Please enter a number.\n");
         //printf("GetNumber is : %d\n",*parrNumb);
         //printf("INDEX IS %i\n",count);
         getnumb=0; /*reinitialize*/

/* FindMax Function
   Input  : Pointer to array
   Process: Finds maximum number in array
   Output : Returns maximum number
int FindMax(int *parrNumb)
    int maxNumb=0; /* used to store maximum number of array */
    int i=0;       /* used as a counter for the array */

    maxNumb = *parrNumb;

    for (i=1; i<10; i++) /* initialize array to 0's */
      *parrNumb++; /* go to next index */
        if (*parrNumb>maxNumb)
           maxNumb = *parrNumb;

    return maxNumb;

/* FindMin Function
   Input  : Pointer to array
   Process: Finds minimum number in array
   Output : Returns minimum number
int FindMin(int *parrNumb)
    int minNumb=0; /* used to store minimum number of array */
    int i=0;       /* used as a counter for the array */

    minNumb = *parrNumb; /* assign first index to minNumb */
    for (i=1; i<10; i++) /* initialize array to 0's */
      *parrNumb++; /* go to next index */
        if (*parrNumb<minNumb)
           minNumb = *parrNumb;

    return minNumb;

/* DisplayNumbers Function
   Input  : Minimum number in array and maximum number in array
   Process: Displays minimum and maximum numbers
   Output : None
void DisplayNumbers(int min, int max)
    printf("\nThe minimum number in the array is %i.",min);
    printf("\nThe maximum number in the array is %i.",max);  
Question by:mathew_s
    LVL 22

    Accepted Solution

    >    *parrNumb++; /* go to next index */

    This line doesnt make much sense-- it's going to increment the integer that parrNumb points to.  
    You probably mean parrNumb++;   that steps the pointer to the next integer in the array.

    >  GetNumbers(arrNumb[10]);   // and other lines passing in arrNumb[10]

    I suspect you meant to pass in just arrNumb.   If you say arrNumb[10], you're passing in the address of the eleventh element of arrNumb, which is probably the wrong thing.
    LVL 1

    Author Comment

    Thanks very much for your advice. Very helpful and informative.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
    Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
    The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now