ref: 682b4cec8835d109e02ab5deb1c4934984fc9eb6
dir: /5551a.c/
#include <stdbool.h> #include <stdio.h> #include <string.h> #include <fcntl.h> enum { NOT = 1, AND, XOR, ADD, RST, /* reset the machine state */ CPY, /* copy stuff from a reg or addr to another */ SET, /* sets mode to bool and int */ OUT }; void main(int argc, char* argv[]) { unsigned int a, b; char string[16], *op; FILE *fd = open("5551.out", O_WRONLY); if(fd < 0) { fprintf(stderr, "unable to open file\n"); return; } while(scanf("%s %[^\n]", op, string) > 0) /* %s removes spaces, what did i expected? */ { sscanf(string, "%u %u", &a, &b); if(!strcmp(op, "NOT")) printf("%u %u\n", NOT, a); if(!strcmp(op, "AND")) printf("%u %u %u\n", AND, a, b); if(!strcmp(op, "XOR")) printf("%u %u %u\n", XOR, a, b); // if(!strcmp(op, "RST")) // reset(): if(!strcmp(op, "CPY")) printf("%u %u %u\n", CPY, a, b); if(!strcmp(op, "SET")) printf("%u %u\n", SET, a); if(!strcmp(op, "OUT")) printf("%u %u\n", OUT, a); if(!strcmp(op, "DIE")) return; } return; }