1

For an assignment I must do a quoridor game, the game must communicate with a referee written in python so that two quoridor clients can play one against other, for some reason what ever I printf at the c program the python instance doesn't receive, or my c program doesn't receive anything from the python referee via scanf

The way I run the referee is like that

./referee.py --black ./quoridor  --white ./quoridor 

The first command that it sends to the ./quoridor is the command "name" and the quoridor must respond with its name, if I run the ./quoridor and type name it works just find,it responds with the name. But thats not the case for the referee.

char command[MAX_COM_SIZE];
scanf("%s",command);
if(strcmpIgnoreCase(command,"name")==0){
    printf("= Athinaios\n\n");
}

The professor have provided me with a binary of a quoridor that works just fine and from the terminal its behaves exactly the same way as mine

sunkuet02
  • 2,376
  • 1
  • 26
  • 33
SteveL
  • 3,331
  • 4
  • 32
  • 57
  • 3
    Buffering maybe? Try `fflush(stdout)`. – kfx Jan 18 '16 at 19:26
  • 3
    What happens if you flush stdout? http://stackoverflow.com/q/1716296/748858 – mgilson Jan 18 '16 at 19:27
  • @kfx ,damn it I was burning brain cells for 2 hours now trying to figure it out and it was this! seems like a usual pit fall that likely has been already awnsered ,should I delete the question or you will post a formal awnser? – SteveL Jan 18 '16 at 19:34
  • @SteveL might be helpful to answer for someone coming via google search, the title is quite specific and probably not an uncommon problem. – kfx Jan 18 '16 at 19:38

2 Answers2

3

The printf() call in your code correctly puts the formatted string to stdout. However, the problem is that C standard library file descriptors are buffered, so the output will not appear until either the buffer is full or is explicitly flushed.

To flush the output, use fflush:

printf("= Athinaios\n\n");
fflush(stdout);

Or alternatively, disable buffering at the start:

setbuf(stdout, NULL);
kfx
  • 8,136
  • 3
  • 28
  • 52
1

There's no reason to do buffered i/o in these kinds of cases. I'd use a write call.

Bing Bang
  • 524
  • 7
  • 16