-
58f9664d :Anonymous
2011-03-13 12:43
-
#include <unistd.h>
/*
* 標準入力からテキストを読んで、2byte毎に\xをつけて出力
* ついでに const char a[] = とかなんとか
*/
#define STDIN 0
#define STDOUT 1
int main()
{
char buf0[1];
char buf1[1];
int count = 0;
write(STDOUT, "const char a[] =\n", 17);
write(STDOUT, "\"", 1);
while (read(STDIN, buf1, 1) > 0){
if (buf1[0] == '\n') {
write(STDOUT, "\"\n\"", 3);
continue;
}
count++;
if ((count % 2) != 0) {
buf0[0] = buf1[0];
continue;
}
write(STDOUT, "\\x", 2);
write(STDOUT, buf0, 1);
write(STDOUT, buf1, 1);
}
if (buf1[0] != '"') {
write(STDOUT, "\"\n", 2);
}
write(STDOUT, ";\n", 2);
return 0;
}
Powered by shinGETsu.