简体   繁体   English

输入字符串,不可打印字符

[英]Input string with non printable chars

In a Linux console when a C program asks for a string (ie username) how can I insert non-printable chars? 在Linux控制台中,当C程序要求输入字符串(即用户名)时,如何插入不可打印的字符?
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. 我更喜欢在需要时键入char,但是我不知道如何编写不可打印的字符。
Thank you 谢谢

Non printable characters have decimal value from 0 to 31. You can print them this way: 不可打印字符的十进制值为0到31。您可以通过以下方式打印它们:

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. 同样,您可以读取字符的整数值。...但是,将它们与可打印字符一起放在一个字符串中,将是另一项艰巨的任务。

It worked using xclip (printf '\\x48\\x83...' | xclip) to copy the string to clipboard. 它使用xclip(printf'\\ x48 \\ x83 ...'| xclip)将字符串复制到剪贴板。
Then, when the program asks for the string, I used SHIFT+CTRL+V to paste the string. 然后,当程序要求输入字符串时,我使用SHIFT + CTRL + V粘贴了字符串。
It generally works, except for certain characters (\\x08, ...) that the input function (gets, ...) can ignore or use as control character. 除了某些字符(\\ x08,...),输入函数(gets,...)可以忽略或用作控制字符外,它通常可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM