Thread: linux beep function

  1. #1
    Registered User
    Join Date
    Dec 2005
    Location
    german border
    Posts
    72

    linux beep function

    Hi,

    I am writing a morse code converter and I am using the Beep() function in the windows header file to make the beep sounds, but I cannot seem to find an equivalent function for linux, man beep doesn't give me anything. Also a sleep function which allowed sleeping for only fractions of a second would be useful as the sleep function in linux doesn't accept decimals.

    Thanks in advance,

    Calef13

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    To be very basic but very portable, you could always print a '\a'.

    Or you could use ANSI escape sequences like this does. http://abcplus.sourceforge.net/beep.c

    You could always use system("beep").
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Location
    german border
    Posts
    72
    oh thanks, I thought that system() was windows only, that will come in handy.

    Calef13

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    The bare basics of the functionality of system() works on both *nix and Windows systems, however, there are problems with writing portable applications for both that use it. For example, to list the contents of a directory, it's ls vs dir.

    Overall, I would recommend against using system() if you don't have to use it.

  5. #5
    Registered User
    Join Date
    Dec 2005
    Location
    german border
    Posts
    72
    Yeah, I usually avoided it anyway, I am only using it for beep but I'll keep that in mind.

    Does anyone know a sleep function which takes milliseconds for input in linux?

    Calef13

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I don't think anything here will help: http://faq.cprogramming.com/cgi-bin/...&id=1043284392

    Do a board search. I've never actually needed such a function, but usleep() comes to mind.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Registered User
    Join Date
    Dec 2005
    Location
    german border
    Posts
    72
    In accordance with MacGyver's advice I'll try and avoid using system("sleep") and try out those functions. The program will be linux/unix only anyway as it uses the c sockets library.

    Calef13

  8. #8
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    Quote Originally Posted by Calef13 View Post
    Does anyone know a sleep function which takes milliseconds for input in linux?
    man usleep. it takes microseconds.
    Code:
           #include <unistd.h>
    
           int usleep(useconds_t usec);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM