Input string with non printable chars

馋奶兔 提交于 2019-12-25 04:19:09

问题


In a Linux console when a C program asks for a string (i.e. username) how can I insert non-printable chars?
I search something better then
printf '\x48\x83\xc4\x50\x48\xbf\x3d...etc' | ./myProgram.bin
or
./myProgram.bin < dataFile
I prefer to type chars when needed but I don't know how to write non-printable ones.
Thank you


回答1:


It worked using xclip (printf '\x48\x83...' | xclip) to copy the string to clipboard.
Then, when the program asks for the string, I used SHIFT+CTRL+V to paste the string.
It generally works, except for certain characters (\x08, ...) that the input function (gets, ...) can ignore or use as control character.




回答2:


Non printable characters have decimal value from 0 to 31. You can print them this way:

void main()    {
int i;
char c;
for(i=0;i<32;i++)     {
   c=i;
   cout<<c<<" ";
 }
getch();
}

Same way, you can read the characters in terms of their integer values....However, putting them alongwith printable characters in one string, would be another uphill task.



来源:https://stackoverflow.com/questions/18945448/input-string-with-non-printable-chars

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!