2
我有一個名爲「ChessMoves.h」的頭文件和一個c文件調用ChessMoves與一堆不同的功能。需要幫助從頭文件調用函數
頭文件
#ifndef __CHESSMOVES_H
#define __CHESSMOVES_H
typedef struct Location
{
// the square's column ('a' through 'h')
char col;
// the square's row (1 through 8)
int row;
} Location;
typedef struct Move
{
// location where this piece is moving from
Location from_loc;
// location where this piece is moving to
Location to_loc;
// what type of chess piece is being moved
char piece;
// whether this move captures another piece
short int isCapture;
// the color of the piece being moved
Color color;
} Move;
文件我打電話給
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ChessMoves.h"
void parseNotationString(char *str, Move *whiteMove, Move *blackMove){
int i, space = 0, j = 0, k = 0, l = 0;
int white[10], black[10], move[10], to[2];
whiteMove.color = WHITE;
if(white[0] > 64)
whiteMove.piece = white[0];
if(white[0] < 64)
whiteMove.from_loc.row = white[0];
for(i = 0; i < 10; i++)
if(white[i] == 'x')
whiteMove.isCapture = 1;
for(i = 0; j < 10; i++)
if(white[i] == ' ')
to[0] = white[i-2];
to[1] = white[i-1];
printf("%c %c", to[0], to[0]);
}
我們得到了一個文件來測試代碼,並在該文件中,他有:
whiteMove.color != WHITE
和如果whiteMove.color不等於白色它將顯示「失敗」,所以我試圖 設置
whiteMove.color = WHITE
但我不斷收到「請求會員'顏色'的東西不是結構或聯盟。我嘗試打電話的其他結構也是一樣。我試過了,
Move.color = WHITE
而且這也不起作用。
你爲什麼要測試未初始化的'white [0]'? – Sergio
考慮到缺少分號,語法都不是C。 – bmargulies
whiteMove.color = WHITE;應該是whiteMove-> color;這是一個指針。 – bmargulies