My simple C programming and chess learning continues as I start looking at a FEN parser in C. I'm just learning this and have adapted some code use strtok();
The code:
Code:
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
char strFEN[] ="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
char * p_ch;
printf ("Splitting FEN string \"%s\" into tokens in C using strtok():\n\n",strFEN);
/*
* Modification needed:
* To print a FEN as a board(table) if char 1-8 is found need to print '-'
* instead of char
* eg
* if p_ch =="1"; then printf("-");
* if p_ch =="2"; then printf("--");
* if p_ch =="3"; then printf("---");
* if p_ch =="4"; then printf("----");
* if p_ch =="5"; then printf("-----");
* if p_ch =="6"; then printf("------");
* if p_ch =="7"; then printf("-------");
* if p_ch =="8"; then printf("--------");
*
* How to do this?!
*
*/
p_ch = strtok (strFEN,"/ -");
while (p_ch != NULL)
{
printf ("%s\n",p_ch);
p_ch = strtok (NULL, "/ -");
}
printf ("\n");
return 0;
}
This needs modifying so that when a numeric char token is found the C code will print '-' (from one to eight dashes but not 1-8 chars as it does now). So I'm grateful for help how I can add this so the FEN string can be parsed and printed as a chess board. I look forward to helpful replies, many thanks