输入字符串,带有不可打印的字符 [英] Input string with non printable chars
问题描述
在Linux控制台中,当C程序要求输入字符串(即用户名)时,如何插入不可打印的字符?
我搜索了更好的东西
printf '\x48\x83\xc4\x50\x48\xbf\x3d...etc' | ./myProgram.bin
或
./myProgram.bin < dataFile
我更喜欢在需要时键入char,但是我不知道如何编写不可打印的字符.
谢谢
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
推荐答案
非可打印字符的十进制值为0到31.您可以通过以下方式打印它们:
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.
这篇关于输入字符串,带有不可打印的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!