The line char coord[2];
declares coord
as an array of characters (also known as a "string"). However, the %c
(in both scanf
and printf)
reads/writes a single character.
For strings, you need to use the %s
format.
Also, if you want to store/read/print the string, "g6"
, you will need to allocate (at least) three characters to your coord
array, as you must terminate all C-strings with a nul
character.
Furthermore, calling fflush
on the stdin
stream is not effective (actually, it causes undefined behaviour, so anything could happen) - see here: I am not able to flush stdin.
So, a 'quick fix' for your code would be something like this:
#include <stdio.h>
int main()
{
char coord[3]; // Allow space for nul-terminator
// fflush(stdin); // don't do it
scanf("%2s", coord); // The "2" limits input to 2 characters
printf("%s\n", coord);
return 0; // ALways good practice to return zero (success) from main
}