Example of my problem:
- Code: Select all
#include <stdio.h>
#include <stdlib.h>
/*
Some unfamiliar syntax in this code might be the
Get* functions. These are from the cs50 library.
The functions take the user's input and converts
it to the data type indicated.
*/
#include <cs50.h>
typedef struct
{
int number;
char *name;
}
player;
int
main(void)
{
// This is where the problem lies, the program is asking the users how many players are on his/her team
printf("Number of Players: \n");
int size = GetInt();
player team[size];
printf("%d\n", sizeof(player));
for (int i = 0; i < size; i++)
{
printf("Player's Number: ");
team[i].number = GetInt();
printf("Player's Name: ");
team[i].name = GetString();
printf("\n");
}
FILE *data = fopen("database", "w");
if (data != NULL)
{
for (int j = 0; j < size; j++)
{
fprintf(data, "%d\n", team[j].number);
fprintf(data, "%s\n", team[j].name);
}
fclose(data);
}
for (int i = 0; i < size; i++)
{
free(team[i].name);
}
}



