so erstellen Sie ein interaktives Menü in C, wechselt von einer Funktion in eine andere, ohne Neuzeichnen des Menüs

Mein Ziel ist zu produzieren ein Programm, das eine Datei als input und "Kodieren" wird der text innerhalb der durch die Verlagerung der Zeichen, die Sie vor 3 (also 'a' kommen 'd'). Es erzeugt eine Ausgabe-Datei mit dem verschlüsselten text. Das Menü ist Benutzer-Eingabe und führen Sie die Funktion aus, die zugewiesen wird, um die Anzahl ausgewählt.

Ich bin früh bei der Erstellung dieses Programm, aber läuft kurze Zeit und bin kämpfen mit, wie Sie zu strukturieren. Heute habe ich das Menü angezeigt, aber wenn eine sub-Funktion aufgerufen wird, zeigt aber dann das Menü überschreibt und ich kann nicht herausfinden, warum. Jede Hilfe würde geschätzt werden. Hier ist der code, den ich bisher...

#include <stdio.h>
#define INPUT_FILE 1    //define statements
#define OUTPUT_FILE 2
#define NUM_TO_SHIFT 3
#define ENCODE 4
#define QUIT 0

int menu();     //function prototypes
int input();
int output();
int shift();
int encode();
void quit();

int main()
{
    int choice;     //main variables
    char user_filename[100];

    choice = menu();   //get user's first selection

    while(choice != QUIT)   //execute so long as choice is not equal to QUIT
    {
        switch(choice)
            {
                case INPUT_FILE:
                    printf("Enter the filename of the file to encode:\n");
                    printf("(hit the Enter key when done)\n");
                    gets(user_filename);
                    break;
                case OUTPUT_FILE: output();
                    break;
                case NUM_TO_SHIFT: shift();
                    break;
                case ENCODE: encode();
                    break;
                case QUIT: quit();
                    break;
                default:    printf("Oops! An invalid choice slipped through. ");
                            printf("Please try again.\n");
            }
      choice = menu(); /* get user's subsequent selections */
   }

   printf("Bye bye!\n");
   return 0;
}

int menu(void)
{
    int option;

    printf("Text Encoder Service\n\n");
    printf("1.\tEnter name of input file (currently 'Secret.txt')\n");
    printf("2.\tEnter name of output file (currently not set)\n");
    printf("3.\tEnter number of characters data should be shifted (currently +7)\n");
    printf("4.\tEncode the text\n\n");
    printf("0.\tQuit\n\n");
    printf("Make your selection: ");

    while( (scanf(" %d", &option) != 1) /* non-numeric input */
          || (option < 0)               /* number too small */
          || (option > 4))              /* number too large */
    {
      fflush(stdin);                    /* clear bad data from buffer */
      printf("That selection isn't valid. Please try again.\n\n");
      printf("Your choice? ");
    }
    return option;
}

int input()
{

}

int output()
{
    return 2;
}

int shift()
{
    return 3;
}

int encode()
{
    return 4;
}

void quit()
{
    printf("Quiting...Bye!");
    exit(0);
}
InformationsquelleAutor user1593866 | 2012-08-14
Schreibe einen Kommentar