c - Shuffle Array ->请求非结构或联合的成员



下面的代码将生成一副牌的所有可能的分割

void divide(CardDeck origDeck, CardDeck * leftDeck, CardDeck * rightDeck)
{
int size = origDeck.size - 1 ;

for (int i = 0; i < size; size++){
int midpoint = i + 1;
int j = 0;
int k = 0;
while (j < midpoint){
leftDeck.cards[j] = origDeck.cards[j];
j++;
}
int remaining = origDeck.size - j;
while (k < remaining){
rightDeck.cards[k] = origDeck.cards[j];
k++;
j++;
}
void interleave(CardDeck leftDeck, CardDeck rightDeck);
}

但是我一直得到这个错误。我试过更换->使用点运算符,但它仍然给出另一个错误

gcc -std=c99 -g -Wall -Wshadow --pedantic -Wvla -Werror -DTEST_INTERLEAVE -DTEST_DIVIDE -DTEST_SHUFFLE -c shuffle.c 
shuffle.c: In function ‘divide’:
shuffle.c:52:15: error: request for member ‘cards’ in something not a structure or union
leftDeck.cards[j] = origDeck.cards[j];
^
shuffle.c:57:16: error: request for member ‘cards’ in something not a structure or union
rightDeck.cards[k] = origDeck.cards[j];
^
make: *** [shuffle.o] Error 1

这是我在替换时收到的错误。使用箭头操作符

shuffle.c: In function ‘divide’:
shuffle.c:52:36: error: invalid type argument of ‘->’ (have ‘CardDeck’)
leftDeck->cards[j] = origDeck->cards[j];
^
shuffle.c:57:37: error: invalid type argument of ‘->’ (have ‘CardDeck’)
rightDeck->cards[k] = origDeck->cards[j];
^
make: *** [shuffle.o] Error 1
bash-4.2$ 

对于头文件,它看起来像这样:

#ifndef SHUFFLE_H
#define SHUFFLE_H
#include <stdlib.h>
#define MAX_SIZE 13
typedef struct
{
char cards[MAX_SIZE];
int size;
} CardDeck;
void divide(CardDeck origDeck, CardDeck* leftDeck, CardDeck* rightDeck);
void interleave(CardDeck leftDeck, CardDeck rightDeck);
void shuffle (CardDeck origDeck);

origDeck改为指针

void divide(CardDeck *origDeck, CardDeck *leftDeck, CardDeck *rightDeck)

leftDeck->cards[j] = origDeck->cards[j];
rightDeck->cards[k] = origDeck->cards[j];

相关内容

  • 没有找到相关文章

最新更新