2008年9月21日星期日

HexString


/**
* File: hexstring.c
* Author: Lvlin
* Date: 星期日, 九月 21 2008
* Abstract: get the C pattern string for inputs
*
*/
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char * argv[])
{
char c=0;
while(EOF != scanf("%c",&c))
{
if('\n' == c)
// ignore the input of carry,
// print it directly
printf("\n");
else
// & 0xFF to keep the only low 8 bits
printf("\\x%x",c & 0xFF);
}
printf("Done!\n");
return 0;
}

没有评论: