the msg was very informative
here's code that i believe captures the input in the struct you're suggesting.
i didn't look over your code that drives hardware.
setMove: 0 a1n (null)
setMove: 1 c2 t120
setMove: 2 d4 t0
setMove: 3 b5 t0
setMove: 4 a2 t368
setMove: 5 e2 t452
setMove: 6 1c t0
setMove: 7 e1 t600
process: 1 (0,0) 0
process: 2 (2,1) 120
process: 3 (3,3) 0
process: 4 (1,4) 0
process: 5 (0,1) 368
process: 6 (4,1) 452
process: 7 (0,2) 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
struct Move_s {
int x;
int y;
unsigned long msec;
};
#define MAX_MOVES 20
Move_s moves [MAX_MOVES];
int moveN;
char str [] = "A1N c2 t120 d4 t0 b5 t0 a2 t368 e2 t452 1c t0 e1 t600";
// -----------------------------------------------------------------------------
int
tokenize (
char *str,
char *tok [],
int maxTok )
{
static char s [100];
strcpy (s, str);
int n;
for (n = 0; n < strlen(s); n++)
s [n] = tolower (s [n]);
tok [0] = strtok (s, " ");
for (n = 1; n < maxTok; n++)
if (NULL == (tok [n] = strtok (NULL, " ")))
break;
return n;
}
// ---------------------------------------------------------
void
setMove (
int idx,
char *pos,
char *msec )
{
printf ("%s: %2d %3s %s\n", __func__, idx, pos, msec);
moves [idx].msec = 0;
if (NULL != msec && 't' == msec[0])
moves [idx].msec = atoi (++msec);
if (isdigit(pos [0])) {
moves [idx].x = pos [0] - '1';
moves [idx].y = pos [1] - 'a';
}
else {
moves [idx].x = pos [0] - 'a';
moves [idx].y = pos [1] - '1';
}
}
// ---------------------------------------------------------
void
translate (
char *tok [],
int nTok )
{
moveN = 0;
setMove (moveN++, tok [0], NULL);
for (int i = 1; i < nTok; i+=2)
setMove (moveN++, tok [i], tok [i+1]);
}
// ---------------------------------------------------------
void
disp ()
{
Move_s *m = moves;
printf ("\n");
for (int i = 1; i < moveN; i++, m++)
printf ("%s: %2d (%d,%d) %4d\n", __func__, i, m->x, m->y, m->msec);
}
// -----------------------------------------------------------------------------
#define MAX_TOK 40
int
main ()
{
char *tok [MAX_TOK];
int nTok = tokenize (str, tok, MAX_TOK);
translate (tok, nTok);
disp ();
}