To preface, I am new to coding, so if there is an entirely obvious issue here that I am missing, I apologise in advance.
I have a bit of code I'm working on where an assortment of names and numbers are read from a file into a struct seen below.
typedef struct KnightsBallLottoPlayer {
char firstName[20];
char lastName[20];
int numbers[6];
} KBLottoPlayer;
I put the scanning of the file itself into its own void function like so, using pointer KBLottoPlayer * player;
in main:
void scanning(KBLottoPlayer*players){
int i, j;
FILE * ifp = NULL;
ifp=fopen("KnightsBall.in", "r");
fscanf(ifp, "%d", &people);
players = malloc(people * sizeof(KBLottoPlayer));
for(i=0;i<people;i++){
fscanf(ifp, "%s%s", &players[i].lastName, &players[i].firstName);
for(j=0;j<6;j++){
fscanf(ifp, "%d", &players[i].numbers[j]);
}
}
}
So far so good, I print out all of these values while in the function immediately afterwards, and they all line up just fine. No issues. They print accurate values and names. I return to main, and print them out again before doing anything else, and suddenly I'm getting random ASCII characters for names and values like -32342342 for numbers.
I will paste more information if needed, but does anyone have any idea as to how this could be? I am going to go out on a limb here and assume that I should be returning something and using a pass by value function instead, but I'm not entirely sure how to proceed from here. Thank you in advance for the help and kind words.