Thread: Interface Question

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    41

    Interface Question

    I'm making a program to enter and store cheats. I have the main menu that comes up asking for your choice. Delete code, Enter code etc. When the user enters the choice it brings up the new menu. But you can still see part of the old menu. How would I go about fixing this so the user only sees the new menu. I tryed using more blank printf(); but that just made the new menu and the ver bottom of the DOS screen. I want it centered like the First main menu. How would i go about doing this?

    I've attaced the soure code if you want to look at it. Pluse could you please look at it and give me feed back on it. This is my first program i'm working on. I would like to know what i'm doing wrong. It only ask you for your menu choices it cant save or search for anything yet. Not that far in the book 20 more pages to go then it will be able to save and search for stuff.

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    41

    One more thing

    My code is about 800 lins so i'm just warning you if you dont have the time too look at it.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    95
    just clear the screen before displaying any menu:

    in dos:
    clrscr();
    or
    system("cls");

    in unix:
    system("clear");

    you could also think about changing your functions so you have a function for enter cheat, passing it the name, ie Dreamcase or Gamecube, which you could use in your printf as we'll as determining where it should be saved as the rest of the checks like making sure it is the right size, etc are all the same, just seems like a lot of functions, but I havent really had a good read so it may be required.

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    41
    That's a good idea. Save me time on making all those functions.
    I'm going to try the clrscr() now thanks.
    Shouldent NULL be, 78, 85, 76, 76, or just 0 or, 4E, 55, 4C, 4C

  5. #5
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    smog890, I'll give an advice. For clearing screen, do not use system ("cls");, beacuse it is too slow.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  6. #6
    Registered User
    Join Date
    May 2002
    Posts
    41
    My compiler wont let me use clrscr(); do you have to put anything in the ()?
    Last edited by smog890; 06-03-2002 at 11:15 AM.
    Shouldent NULL be, 78, 85, 76, 76, or just 0 or, 4E, 55, 4C, 4C

  7. #7
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Thumbs up

    You should wrote clrscr (); and not clrscrn();.

    Definition of the clrscr (); function is: void clrscr (void);
    You don't have to put anything in ().
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    OK, here's some thoughts on your program in general:

    >fflush(stdin);
    Don't do this, it's wrong. Learn other ways of clearing the input buffer.

    >main()
    You have recursive calls to main. This is bad programming style, and you should avoid it unless you're trying to confuse other people who read your source. Only the OS should call main().

    >scanf("%d", &selection );
    Always check the return code of scanf(). If the user enters a character instead of a number, the value of selection won't be what you think.

    >function return statement
    You have some functions that are defined as returning a value, but don't.

    >in function update(): if(UpdateExit == 1);
    This line of code has no affect as it is terminated with a semi-colon. There are more examples of this same problem in other functions, I'll let you find them.

    Code:
    puts("\n\nEnter code to delete: ");
    		fflush(stdin);
    		scanf("%s", delete_catigory[maxinput]);
    			if(delete_catigory[maxinput] < maxinput);
    Your indentation has gone a bit wrong in the above example. Try to indent properly, it makes the code easier to follow.

    >char enter_n64[maxinput];
    >scanf("%s", enter_n64[maxinput]);
    scanf() needs a pointer as it's second parameter. You have passed a char. This will break the program. Also, fgets() is better for obtaining input than scanf() for various reasons.

    >more recursive function calling (in like, a whole bunch of functions.) Try using loops to control the code when doing user input validation.

    Code:
    if(goodbye == 'y')    
    	exit;             
    else                  
    	if(goodbye == 'n')
    	main();           
    else                  
    	exit_y_n();
    The above is bad coding style for lots of reasons
    - The exit call has no affect, exit is a function that requires a parameter.
    - Again you're calling main() which is a no no.
    - And you have a recursive call to exit_y_n() which would be better controlled via a loop of some sort.

    You appear to have a lot of functions that all do a very similar thing. Why not consolidate them into one, and pass parameters for the bits you need to make variable.

    To show you the trouble I had with your code, here's the output from my compiler:
    Code:
    Borland C++ 5.5 for Win32 Copyright (c) 1993, 2000 Borland
    smog.c:
    Warning W8065 smog.c 142: Call to function 'main' with no prototype in function main
    Warning W8065 smog.c 255: Call to function 'main' with no prototype in function search_for_cheat
    Warning W8065 smog.c 360: Call to function 'main' with no prototype in function enter_cheat
    Warning W8065 smog.c 429: Call to function 'main' with no prototype in function delete_cheat
    Warning W8066 smog.c 449: Unreachable code in function delete_cheat
    Warning W8065 smog.c 492: Call to function 'main' with no prototype in function history
    Warning W8066 smog.c 506: Unreachable code in function history
    Warning W8065 smog.c 532: Call to function 'main' with no prototype in function help
    Warning W8070 smog.c 539: Function should return a value in function help
    Warning W8070 smog.c 558: Function should return a value in function help_search
    Warning W8070 smog.c 577: Function should return a value in function help_enter_cheat
    Warning W8070 smog.c 596: Function should return a value in function help_delete_cheat
    Warning W8019 smog.c 609: Code has no effect in function update
    Warning W8065 smog.c 610: Call to function 'main' with no prototype in function update
    Warning W8019 smog.c 629: Code has no effect in function exit_y_n
    Warning W8065 smog.c 632: Call to function 'main' with no prototype in function exit_y_n
    Warning W8070 smog.c 637: Function should return a value in function exit_y_n
    Warning W8019 smog.c 648: Code has no effect in function search_all_catigorys
    Warning W8070 smog.c 653: Function should return a value in function search_all_catigorys
    Warning W8019 smog.c 663: Code has no effect in function n64_search
    Warning W8070 smog.c 667: Function should return a value in function n64_search
    Warning W8019 smog.c 677: Code has no effect in function playstation_search
    Warning W8070 smog.c 680: Function should return a value in function playstation_search
    Warning W8019 smog.c 691: Code has no effect in function playstation2_search
    Warning W8070 smog.c 694: Function should return a value in function playstation2_search
    Warning W8019 smog.c 704: Code has no effect in function dreamcast_search
    Warning W8070 smog.c 707: Function should return a value in function dreamcast_search
    Warning W8019 smog.c 718: Code has no effect in function gamecube_search
    Warning W8070 smog.c 721: Function should return a value in function gamecube_search
    Warning W8019 smog.c 732: Code has no effect in function xbox_search
    Warning W8070 smog.c 735: Function should return a value in function xbox_search
    Warning W8019 smog.c 746: Code has no effect in function pc_search
    Warning W8070 smog.c 749: Function should return a value in function pc_search
    Warning W8019 smog.c 760: Code has no effect in function enter_new_catigory
    Warning W8070 smog.c 766: Function should return a value in function enter_new_catigory
    Warning W8019 smog.c 777: Code has no effect in function enter_n64_cheat
    Warning W8070 smog.c 781: Function should return a value in function enter_n64_cheat
    Warning W8019 smog.c 791: Code has no effect in function enter_ps_cheat
    Warning W8070 smog.c 795: Function should return a value in function enter_ps_cheat
    Warning W8019 smog.c 805: Code has no effect in function enter_ps2_cheat
    Warning W8070 smog.c 809: Function should return a value in function enter_ps2_cheat
    Warning W8019 smog.c 819: Code has no effect in function enter_dc_cheat
    Warning W8070 smog.c 823: Function should return a value in function enter_dc_cheat
    Warning W8019 smog.c 833: Code has no effect in function enter_gc_cheat
    Warning W8070 smog.c 837: Function should return a value in function enter_gc_cheat
    Warning W8019 smog.c 847: Code has no effect in function enter_xbox_cheat
    Warning W8070 smog.c 851: Function should return a value in function enter_xbox_cheat
    Warning W8019 smog.c 861: Code has no effect in function enter_pc_cheat
    Warning W8070 smog.c 865: Function should return a value in function enter_pc_cheat
    Warning W8019 smog.c 875: Code has no effect in function delete_cheat_catigory
    Warning W8070 smog.c 878: Function should return a value in function delete_cheat_catigory
    Warning W8019 smog.c 888: Code has no effect in function delete_cheat_code
    Warning W8070 smog.c 892: Function should return a value in function delete_cheat_code
    Warning W8019 smog.c 902: Code has no effect in function delete_code_catigory
    Warning W8070 smog.c 905: Function should return a value in function delete_code_catigory
    Warning W8070 smog.c 915: Function should return a value in function his_nintendo
    Warning W8070 smog.c 924: Function should return a value in function his_sega
    Warning W8070 smog.c 932: Function should return a value in function his_sony
    Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    Registered User
    Join Date
    May 2002
    Posts
    41
    oh wow, all the functions that get the input do nothing now becuase i'm not that far in the book. well i'm going to go to work on my program now. Thanks for your help.
    Shouldent NULL be, 78, 85, 76, 76, or just 0 or, 4E, 55, 4C, 4C

  10. #10
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by smog890
    oh wow, all the functions that get the input do nothing now becuase i'm not that far in the book.
    I guess as much To shut the compiler up, you can just add a return 0; statement to each of the functions that require it.

    Trouble is, if you have too many error messages being generated, it becomes hard to tell the good from the bad.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  11. #11
    Registered User
    Join Date
    May 2002
    Posts
    41
    would this work for fflush(); This is an example in the book i'm reading. Should I use this way?



    void clear_kb( void );

    int main()
    {
    /*code that gets input here*/



    /*Now call clear_kb(); to clear input buffer*/
    clear_kb();

    /*Now code to get second input*/

    }


    /*Clear input buffer function*/
    void clear_kb( void )
    {
    char junk[80];
    gets(junk);
    }







    Thanks for looking at my code.
    Shouldent NULL be, 78, 85, 76, 76, or just 0 or, 4E, 55, 4C, 4C

  12. #12
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    In short.... no.

    I should point out that gets() is bad. It doesn't do any bounds checking, so if the user enters too many characters, the buffer will overflow. It is a function that I see many newbies use, presumably because they have a lame teacher or book.

    A better way to flush stdin is to
    >while (getchar() != '\n');
    This will read in a character at a time, until the newline is reached. All characters are discarded.

    It does however assume that there is actually garbage in the buffer. If there isn't (meaning the buffer is already empty), then the user will need to press enter again to satisfy the loop, which is not a user-friendly situation. Use it with care!
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. OOP in C
    By lyx in forum C Programming
    Replies: 4
    Last Post: 11-23-2003, 01:12 PM
  3. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  4. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM
  5. simple input and string manipulation question
    By Stig in forum C Programming
    Replies: 1
    Last Post: 12-15-2001, 01:33 PM