fork(2) download
  1. #include <stdio.h>
  2. #include <string.h> //for memset
  3.  
  4. int main(void) {
  5. char cmd[255];
  6. memset(cmd, 0, 255);
  7. do
  8. {
  9. // read
  10. fgets(cmd, 255, stdin);
  11. cmd[strcspn ( cmd, "\n")] = '\0';
  12.  
  13. // TODO: do some stuff
  14. if(!strcmp(cmd, "start"))
  15. printf("Starting the game.\n");
  16.  
  17. } while(!strcmp(cmd, "eixt")); // do until cmd does not equal exit
  18. printf("Exiting the command line.");
  19. return 0;
  20. }
  21.  
Success #stdin #stdout 0s 2172KB
stdin
start
exit
stdout
Starting the game.
Exiting the command line.