这是我正在处理的作业的头文件中的一个函数。
#ifndef CARDGAMES_H
#define CARDGAMES_H
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
typedef struct {
char suit;
char label;
int value;
} card ;
//function prototypes (removed the majority of them, this is just a segment of header file)
void addToDeck(card deck[], card toAdd, int * deckLength);
void printDeck(card deck[], int deckLength);
card removeCard(card deck[], int * deckLength, int index);
*/
card removeCard(card deck[], int * deckLength, int index){
card removed = deck[index];
int x = *deckLength;
deck[index] = deck[x];
deck[x] = removed;
x=x-1;
*deckLength = x;
return removed;
以下是我正在测试此功能的驱动程序的一部分......我的问题出现了。
printf("\tThe deck after adding the ten of hearts: \n");
printDeck(deck, ncards);
printf("Testing removeCard.\n");
removeCard(deck, &ncards, 0);
printf("\tThe deck after removing the first card: ");
printDeck(deck, ncards);
下面是我运行编译后的程序后的输出:
The deck after adding the ten of hearts:
King of hearts
King of spades
King of diamonds
Queen of diamonds
ten of hearts
Testing removeCard.
The deck after removing the first card: ten �?D
King of spades
King of diamonds
Queen of diamonds
这就像我想要的那样做。然而,红桃十没有正确打印。里面有??D?谁能解释我在这里出错的地方?