Thread: Beeps and form feeds???

  1. #1
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127

    Beeps and form feeds???

    I have been trying to add stuff to my programs and can't figure this out. The only two things that work in printf() are \n and \t. I have tried using \f and \a and neither of them do what they should. Am I doing something wrong???
    ~Sven

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    how do we know if you're doing something wrong unless you post what you tried ... ?

    EDIT:

    also, are your sound properties set up to be happy with playing sound back to you?
    Last edited by twomers; 02-23-2006 at 11:30 AM.

  3. #3
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    Parts of some of the tries...
    Code:
    printf("\f"):
    goto mainmenu;
    to get it to clear the screen before printing out the menu again.
    Also...
    Code:
    printf("Invalid Response!\a");
    to get it to beep when they enter an invalid character.
    My book says that those should work but they don't seem to. Anything that I am doing wrong?
    ~Sven

  4. #4
    ex-DECcie
    Join Date
    Dec 2005
    Posts
    125
    The \f escape sequence is a form feed.

    Depending on what type of screen you're printing to, it may well not clear the screen at all or do anything.

    In the old teletype days a form feed would scroll the paper up some specific number of lines. In CRT days (by that I mean dumb terminals) it would scroll the screen up -- sometimes a full screen, sometimes not, depending on all sorts of conditions.

    You might want to look for an OS specific call to clear the screen -- it won't be portable, but will do what you want.

  5. #5
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    like system("cls"); on Windows?

  6. #6
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499
    Also, don't use goto. If there's any way to avoid it, then avoid it. It's considered bad programming practise and makes your code hard to read.

  7. #7
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    I know that but I made the program a while ago and have been improving it but at the time I didn't really know how to do it better. It works like this and I am putting final touches on it before starting another big project so I don't think that it will be worth it to go to the trouble of fixing it. Anyone have any tips on ways to replace goto?

  8. #8
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Quote Originally Posted by 00Sven
    Anyone have any tips on ways to replace goto?
    If you're using it for looping, use a for loop or a while loop. It depends on what you're using it for.

  9. #9
    Registered User
    Join Date
    Mar 2005
    Posts
    11
    Quote Originally Posted by 00Sven
    Anyone have any tips on ways to replace goto?
    Depending on what you are using it for, you might also want to replace it by implementing different functions/procedures.

  10. #10
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    I am using it for just returning to the beginning of the program where there is a menu and then a switch/case of the different options where each option ends in goto mainmenu; except for the case where the user says to exit. I could not think of a better way to do this.
    ~Sven

  11. #11
    Registered User
    Join Date
    Mar 2005
    Posts
    140
    Code:
    do 
    {
      print_menu()
      process_menu_choice()
    } while(menu_choice != terminal_value);

  12. #12
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    Thanks for the help with the goto but that is not what this thread is supposed to be about. Anyone know what is wrong with the beep??
    ~Sven

Popular pages Recent additions subscribe to a feed