#include #include #include uint32_t read_be32(void) { uint32_t x = getchar(); x = (x << 8) | getchar(); x = (x << 8) | getchar(); x = (x << 8) | getchar(); return x; } int main(void) { // Test 0x02: putchar(0x02); putchar(0); putchar(0); putchar(0); putchar(46); printf("Hello World! Type the following string: 12345\n"); // Test 0x01: putchar(0x01); if(getchar() != 0x1) exit(1); uint32_t x = read_be32(); if(x != 0x0000005) exit(1); char buf[5]; fread(buf, 1, 5, stdin); if(buf[0] != '1' || buf[1] != '2' || buf[2] != '3' || buf[3] != '4' || buf[4] != '5') exit(1); // Test 0x03: putchar(0x03); putchar(0); putchar(0); putchar(0); putchar(7); printf("stderr\n"); // Test 0x04, 0x05, 0x06: putchar(0x04); if (getchar() != 0x4) exit(1); int c = getchar(); putchar(0x05); putchar(c); putchar(0x06); putchar(c); // Test 0x07: putchar(0x07); putchar(0); putchar(0); putchar(0); putchar(10); if (getchar() != 0x7) exit(1); x = read_be32(); if(x != 0x000000a) exit(1); // Parrot it: char b2[10]; fread(b2, 1, 10, stdin); putchar(0x02); putchar(0); putchar(0); putchar(0); putchar(10); fwrite(b2, 1, 10, stdout); // Test 0x08: }