Created
October 22, 2014 17:01
-
-
Save cmastudios/0a51833ea61dd2a3921a to your computer and use it in GitHub Desktop.
dylan command process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
#include "string.h" | |
#include "windows.h" | |
void process_command(char *line); | |
int main() | |
{ | |
int c = 0; | |
int position = 0; | |
#define line_max 256 | |
char line[line_max]; | |
while ((c = getchar()) != EOF) { | |
if (c == '\n') { | |
line[position] = '\0'; // strings are null terminated | |
process_command(line); // call our function | |
position = 0; // reset the memory storage | |
} else { | |
line[position] = c; | |
position += 1; | |
if (position >= line_max) | |
return 1; // quit program | |
} | |
} | |
} | |
void process_command(char *line) | |
{ | |
if (strcmp(line, "beep") == 0) { | |
Beep(523,500); | |
printf("\aAre you a robot?\n"); | |
} else { | |
printf ("Unknown command %s.\n", line); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment