I have a header file called "ChessMoves.h" and a c file call ChessMoves with a bunch of different functions.
Header file
#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;
File I'm calling to
#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]);
}
We were given a file to test the code and in that file he has:
whiteMove.color != WHITE
and if whiteMove.color does not equal WHITE it will display "FAIL" so I tried setting
whiteMove.color = WHITE
but I keep getting "request for member 'color' in something not a structure or union. The same thing goes for the other structs I try to call. I tried making it,
Move.color = WHITE
and that doesn't work either.
white[0]?whiteMoveandblackMoveare both pointers, you need to either use the->operator (whiteMove->color) or dereference the pointer before applying the.operator ((*blackMove).color).ifstatement. And now you know why braces are good style. :)