Я пытаюсь распечатать сплетенные строки из массива указателей на константные символы, но отображаемый текст абсолютно мусор. Я не уверен, что пошло не так. Я сократил код для удобства чтения ниже:
#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define HAND_CARDS 5 /* maximum number of cards any particular Hand */
typedef struct card {
int suit;
int face;
} Card;
typedef struct hand {
struct card pHand[5];
int hQuality;
} Hand;
void print_pHand(struct hand player, const char* suit[], const char* face[]);
int main(void)
{
/* initialize memory arrays of suit and face, to be referenced through out the game */
const char *suit[4] = {"Hearts", "Diamonds", "Clubs", "Spades"};
const char *face[13] = {"Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen", "King"};
int deck[4][13] = { 0 };
Hand pHuman = { 0 };
print_pHand(pHuman, suit, face);
return 0;
}
void print_pHand(struct hand player, const char* suit[], const char* face[])
{
int f = 0, s = 0, i = 0;
for (i = 0; i < HAND_CARDS; ++i) {
s = player.pHand[i].suit;
f = player.pHand[i].face;
printf("[%s : %s]\t", suit[s], face[f]);
}
}
Я изменил часть printf (), и она все еще выдает ту же проблему.
Unhandled exception at 0x79B81F4C (ucrtbased.dll) in PA7.exe:
0xC0000005: Access violation reading location 0xF485A8D3. occurred
![enter image description here](https://i.stack.imgur.com/TVD3C.jpg)
Похоже, что есть проблема с доступом к памяти, но я не уверен, как ее исправить.
Примечание: Предполагая, что карты уже были розданы каждому игроку случайным образом, хотя я мог пропустить какая-то важная часть. Так что для полного кода, пожалуйста, посмотрите на мой github здесь:
https://github.com/karln-create/PA7-5CDPoker