Pointers and printing distinct elements in array
Code:
#include <stdio.h>
#include <stdlib.h>
void main()
{
int *currentPoint, *pointerData, *newPoint;
int i=0, n=0, j=0, freq=0;
printf("Enter the number of random integers to be generated: ");
scanf("%d", &n);
while (n<0)
{
printf("Enter the number of random integers to be generated: ");
scanf("%d", &n);
}
//allocate unused space for the array
pointerData = (int*) calloc (n, sizeof(int));
if (pointerData==NULL)
exit (1);
//set current point to first value in array
currentPoint=pointerData;
for (i=0; i < n; i++)
//create random array
*(currentPoint+i) = rand() % 10 + 1;
}
Ive created an array using pointers that lets the user generate a random array of 'n' numbers.
Now I need to output, for example:
10 occurs 4 times
6 occurs 7 times
2 occurs 1 times
Whats the best way to get an output like this because Im completely lost?
I cannot use array indices and the final version should contain no ‘square’ brackets.
Thanks