C - printf("\a") 不会发出警报 [英] C - printf("\a") won't sound an alert

查看:64
本文介绍了C - printf("\a") 不会发出警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的 C 代码.

#include <stdio.h>

int main(){
   printf("\a\n");
   printf("Startled by the sudden sound, Sally shouted, \"By the Great Pumpkin, what was that!?\"");
   return 0;
}

据说,\a\n"应该发出警报,对吗?然而,出于某种原因,它并没有这样做.我在 Ubuntu Zesty 上,bash 命令 beep 确实发出哔哔声,但 echo -e '\a' 没有,所以我不确定是什么问题正是如此.

Supposedly, "\a\n" is supposed to sound an alert right? For some reason, however, it's not doing so. I'm on Ubuntu Zesty, the bash command beep does sound a beep, but echo -e '\a' doesn't, so I'm not sure what the problem is exactly.

提出这个问题是因为其他此类问题最终没有给出对我来说足够详细/易于理解的答案,或者有一个完全不同的问题,其解决方案不适用于我.

Made this question because other such questions didn't end up producing answers that were detailed/understandable enough to me, or had a different problem entirely whose solution didn't apply to me.

坦率地说,上面链接的帖子的答案太含糊了.问题不在于 C,而在于别的东西."根本没有帮助.

The post linked above, frankly, had an answer that was too vague. "The problem isn't with C, it's with something else." doesn't help at all.

更新: 以防万一其他人偶然发现了这一点,这里是问题所在:我有 GNOME,因此 WM 是 Gnome-Shell.既然是这样,我不得不打开声音设置,转到警报,启用它们,并调高音量.我从来没有注意到外壳本身可能是问题所在.在运行 metacity --replace 并突然能够听到警报后意识到这一点.

UPDATE: Just incase someone else stumbles onto this, here was the problem: I have GNOME, and the WM is Gnome-Shell as a result. Since that was the case, I had to open the sound settings, travel over to alerts, enable them, and make the volume higher. It never came to my attention that the shell itself could have been the problem. Realised this after running metacity --replace and suddenly being able to hear alerts.

推荐答案

您确实写对了:附加的 \n 是不延迟哔声输出的惯用方式.

You have indeed written this correctly: and the appended \n is the idiomatic way of not delaying the beep output.

但是,可惜现代操作系统允许用户配置他们的环境,所以这样的哔哔声是可以抑制的.这可能就是这里发生的事情:更深入地研究您的问题,似乎您的外壳已禁用标准输出的哔哔声.

But alas modern operating systems allow users to configure their environment so such beeps are suppressible. That's probably what's happening here: looking a little deeper into your question it seems that your shell has disabled beeping on standard output.

这篇关于C - printf("\a") 不会发出警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆