Skip to content

Instantly share code, notes, and snippets.

@cmastudios
Created October 22, 2014 17:01
Show Gist options
  • Save cmastudios/0a51833ea61dd2a3921a to your computer and use it in GitHub Desktop.
Save cmastudios/0a51833ea61dd2a3921a to your computer and use it in GitHub Desktop.
dylan command process
#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