我有这段代码,但编译时会出现一些错误。如何从普通数组复制到结构数组?
[错误]预计标识符或 '(' 前 '[' 令牌
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
//functions
void createdeck();
//structures
typedef struct card{
int val;
char face;
char suit;
}deck[52];
//global variables
const char suits[4] = { 'D', 'C', 'H', 'S' };
const char face[13] = { '2', '3', '4', '5', '6', '7', '8', '9', 'X', 'J', 'Q', 'K', 'A' };
int main()
{
createdeck();
}
void createdeck()
{
int ctr1,ctr2,count = 0;
for (ctr1 = 0; ctr1 < 4;ctr1++)
{
for (ctr2 = 0;ctr2 < 13; ctr2++)
{
deck[count].val = count + 1;
deck[count].face = face[ctr2];
deck[count].suit = suit[ctr];
count = count + 1;
}
}
}
[错误]预计标识符或 '(' 前 '[' 令牌 这是编译器说什么
deck[count].val = count + 1;
deck[count].face = face[ctr2];
deck[count].suit = suit[ctr];
这些都是突出显示的错误。 请赐教,我还是一个初学者。
你的数组不适合'套装' – JHH
'deck'是一种类型,不可变。像甲板aDeck;'...'aDeck [count] .val'添加变量... ... – BLUEPIXY
'西装[ctr]'错字作为'西装[ctr1]'。 – BLUEPIXY