I am attempting to make a program to track a collection of baseball cards. I'm simulating buying packs of 7 cards and am trying to complete the total collection (which contains 500 unique cards). To do this, I assume that each card has a value from 0-499 and I've created a function to simulate buying packs of 7 cards with unique numbers in each pack. However, the program doesn't seem to work and ends up crashing. Some help would be much appreciated. Here is my program (which isn't entirely completed yet):
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int (*newDeck(int n)) //My function to generate a pack of 7 cards
{
int b[n];
int *(deck);
deck = &b;
int rn;
for (int i = 0; i < 7; i++)
{
rn = rand();
deck[i] = rn%500;
}
return deck;
}
int main()
{
int collection[500][2], *deck;
for (int i = 0; i < 500; i++) //Populating the array of the entire collection
{
collection[i][0] = i;
collection[1][1] = 0;
}
srand(time(NULL)); //Calling the function and filling it with random numbers
deck = *newDeck(7);
printf("%d\n", *newDeck(7));
for (int i = 0; i < 7; i++) // Adding the numbers generated to the entire collection
{
(collection[deck[i]][1])++;
}
}
return 0; //There's more to do but that's all I've done so far and it doesn't work
}