2種類のデータをリンクリストに入れようとしています。例えば:
rotate 0
move 100
rotate 270
move 100
pattern #
rotate 0
draw 50
rotate -30
draw 100
rotate -90
これは最初に文字列rotate
であり、次に整数 0
です。
私はそれをこのように宣言します:
typedef struct NODE
{
char command[6];
int number;
struct NODE *next;
} NODE;
文字列と変数を初期化するには:
char command1[6];
int num = 0;
次に、リストに入力するには、次の関数を使用しますaddnode
。
void addnode(NODE *llist, char command1[6], int num)
{
while (llist->next != NULL)
llist = llist->next;
llist->next = (NODE *)malloc(sizeof( NODE));
llist->next->command[6] = command1[6];
llist->next->number = num;
llist->next->next = NULL;
}
そして、入力するには:
scanf("%s, %d"&command1, &num);
append_node(llist,command1, num);`
エラーが発生します:
行でscanf
:invalid operands to binary & (have ‘char *’ and ‘char *’)
関数の終わりにaddnode
:expected declaration or statement at end of input