add printf esc program

This commit is contained in:
Neale Pickett 2012-11-03 21:43:56 -06:00
parent 49ff09dc9e
commit 456102b59e
2 changed files with 29 additions and 0 deletions

View File

@ -1,5 +1,6 @@
CFLAGS = -Wall -Werror
TARGETS = pmerge puniq p4split hd
TARGETS += pyesc printfesc
all: $(TARGETS)

28
printfesc.c Normal file
View File

@ -0,0 +1,28 @@
#include <stdio.h>
int
main(int argc, char *argv[])
{
printf("printf ");
while (! feof(stdin)) {
int c = getchar();
switch (c) {
case EOF:
break;
case '0' ... '9':
case 'A' ... 'Z':
case 'a' ... 'z':
putchar(c);
break;
default:
printf("\\\\%03o", c);
break;
}
}
putchar('\n');
return 0;
}