[OT]一个C语言的问题

19 views
Skip to first unread message

包乾

unread,
Nov 8, 2015, 9:17:51 AM11/8/15
to sh...@googlegroups.com
以下是一个我在自学K&R第二章bitwise运算符时候写的一个显示程序,单纯想检验一下'~'这个运算符的作用。

#include <stdio.h>
int main(){
int c;

for(c=0;c<15;c++){
printf("%d\t%d\t%u\t%c\t%c\n",c,~c,~c,~c,c);
}
return 0;
}

奇怪的是我在bash中运行这个程序以后,bash的提示符变成了乱码状。
到底发生了什么?

Shell Xu

unread,
Nov 8, 2015, 12:10:01 PM11/8/15
to shlug
你的提示符不应该变成乱码,至少我觉得不大合理。你的c取值在0-15之间,加上~算符后,实际上输出了很多控制字符。
https://zh.wikipedia.org/wiki/%E6%8E%A7%E5%88%B6%E5%AD%97%E7%AC%A6
但是要设定提示符(准确说是终端标题),需要^[(ESC)。这个好像你没打过。所以应该是输出模式出现了什么问题。你照表分析看看?


--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了 Google 网上论坛的“Shanghai Linux User Group”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
要查看更多选项,请访问 https://groups.google.com/d/optout



--
彼節者有間,而刀刃者無厚;以無厚入有間,恢恢乎其於游刃必有餘地矣。
blog: http://shell909090.org/blog/

依云

unread,
Nov 8, 2015, 12:31:17 PM11/8/15
to sh...@googlegroups.com
On Mon, Nov 09, 2015 at 01:09:17AM +0800, Shell Xu wrote:
> 你的提示符不应该变成乱码,至少我觉得不大合理。你的c取值在0-15之间,加上~算符后,实际上输出了很多控制字符。
> https://zh.wikipedia.org/wiki/%E6%8E%A7%E5%88%B6%E5%AD%97%E7%AC%A6
> 但是要设定提示符(准确说是终端标题),需要^[(ESC)。这个好像你没打过。所以应该是输出模式出现了什么问题。你照表分析看看?

是这个:

https://en.wikipedia.org/wiki/Shift_Out_and_Shift_In_characters

--
Best regards,
lilydjwg

Linux Vim Python 我的博客:
http://lilydjwg.is-programmer.com/
--
A: Because it obfuscates the reading.
Q: Why is top posting so bad?

Shell Xu

unread,
Nov 8, 2015, 9:35:46 PM11/8/15
to shlug
make sense

--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了 Google 网上论坛的“Shanghai Linux User Group”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
要查看更多选项,请访问 https://groups.google.com/d/optout

包乾

unread,
Nov 9, 2015, 12:49:38 AM11/9/15
to sh...@googlegroups.com

的确就是这个现象,多谢指点!

2015/11/09 2:31 "依云" <lily...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages