fluffy/printfesc.c

41 lines
501 B
C
Raw Normal View History

2012-11-03 21:43:56 -06:00
#include <stdio.h>
2013-07-23 16:30:38 -06:00
#include <ctype.h>
2012-11-03 21:43:56 -06:00
int
main(int argc, char *argv[])
{
2013-01-29 21:53:17 -07:00
printf("printf ");
2012-11-03 21:43:56 -06:00
2013-01-29 21:53:17 -07:00
while (!feof(stdin)) {
int c = getchar();
2012-11-03 21:43:56 -06:00
2013-01-29 21:53:17 -07:00
switch (c) {
case EOF:
break;
2013-07-23 16:30:38 -06:00
case '\n':
printf("\\n");
break;
case '\r':
printf("\\r");
break;
case '\t':
printf("\\t");
break;
case '"':
printf("\\\"");
2013-01-29 21:53:17 -07:00
break;
default:
2013-07-23 16:30:38 -06:00
if (isprint(c)) {
putchar(c);
} else {
printf("\\%03o", c);
}
2013-01-29 21:53:17 -07:00
break;
}
}
2012-11-03 21:43:56 -06:00
2013-01-29 21:53:17 -07:00
putchar('\n');
2012-11-03 21:43:56 -06:00
2013-01-29 21:53:17 -07:00
return 0;
2012-11-03 21:43:56 -06:00
}