Created
July 17, 2013 00:07
-
-
Save joshkunz/6016412 to your computer and use it in GitHub Desktop.
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
/* Simple quoted translation program. It reads characters from | |
* stdin and writes them to standard out replacing all | |
* instances of the character 'WHAT' with the character 'WITH'. | |
* If a 'WHAT' character appears between 'QSTART' and 'QEND' | |
* (the starting and ending quote characters) it is not | |
* replaced. */ | |
#include <stdio.h> | |
#include <stdbool.h> | |
#define QSTART '"' | |
#define QEND '"' | |
#define WHAT '|' | |
#define WITH ',' | |
int main() { | |
char byte = 0; | |
bool quoted = false; | |
while (! feof(stdin)) { | |
fread(&byte, 1, 1, stdin); | |
if ((! quoted) && byte == QSTART) { | |
quoted = true; | |
} else if (quoted && byte == QEND) { | |
quoted = false; | |
} | |
if ((! quoted) && byte == WHAT) { byte = WITH; } | |
fwrite(&byte, 1, 1, stdout); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment