Forum

> > Off Topic > "\a" Alert character in C/C++
ForenübersichtOff Topic-ÜbersichtEinloggen, um zu antworten

Englisch "\a" Alert character in C/C++

11 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt "\a" Alert character in C/C++

DannyDeth
User Off Offline

Zitieren
Hi there,

I was coding a small program just now ( bored + no one interesting on Skype ) and thought about how to alert someone using the program. I remember the old \a alert character and now I'm obsessed with trying to find out how to actually make the beep, lol.
Any answers are appreciated.

Thanks,
Danny

alt Re: "\a" Alert character in C/C++

Wolf6331
User Off Offline

Zitieren
The alert character does only work on unix systems. But i am not to 100% sure.

on windows you need to include windows.h and use the "Beep" function:

void Beep ( int duration, int frequency );

alt Re: "\a" Alert character in C/C++

DannyDeth
User Off Offline

Zitieren
@Lee:
1
2
3
4
5
6
#include <stdio.h>

int main(void){
	printf("\7");
	return 0;
}
Surely something like this wouldn't work.. ( compiling... )

EDIT: it isn't working. No errors.
I'm using TCC ( don't have GCC on this machine ).

alt Re: "\a" Alert character in C/C++

Lee
Moderator Off Offline

Zitieren
Hmm, that's strange, but if ctrl+G is generating a beep, then we know that there must at least be some beep control character.

If you have python installed, can you do the following? (I'm assuming standard tty terminal)

type in a = "
hit ctrl+G
close off the quotes
type in a and enter to see what its ascii code is

Then test it by doing print a, if you get the beep, then it means we got the code right, otherwise you're probably not using a standard terminal.

alt Re: "\a" Alert character in C/C++

KimKat
GAME BANNED Off Offline

Zitieren
Try using tput bel or alternatively /bin/echo -e "\a" in order to create a beep sound. If it doesn't work for NetBSD then possibly it may work on Linux.

alt Re: "\a" Alert character in C/C++

archmage
User Off Offline

Zitieren
user DannyDeth hat geschrieben
@Lee:
1
2
3
4
5
6
#include <stdio.h>

int main(void){
	printf("\7");
	return 0;
}
Surely something like this wouldn't work.. ( compiling... )

EDIT: it isn't working. No errors.
I'm using TCC ( don't have GCC on this machine ).


Really? It works for me. I am using GCC must be TCC.
Lol
1
2
while (true)
	printf("\7");
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antwortenOff Topic-ÜbersichtForenübersicht