Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8373373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:39:40+00:00 2026-06-09T14:39:40+00:00

My goal is to produce a program that will take a file as input

  • 0

My goal is to produce a program that will take a file as input and “encode” the text within by shifting the characters ahead 3 (so ‘a’ would be come ‘d’). It should produce an output file with the encoded text. The menu is to take user input and execute the function that is assigned to the number selected.

I’m early on at creating this program, but running short on time and am struggling with how to structure it. Currently, I have the menu displaying, but when a sub function is called, it displays but then the menu overwrites it and I can’t figure out why. Any help would be appreciated. Here is the code I have so far…

#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);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:39:42+00:00Added an answer on June 9, 2026 at 2:39 pm

    You shouldn’t use gets(user_filename) to get the file name since gets() reads up to a \n and stops reading. Your scanf for the menu option does not read the \n at the end of the line when the user types in the menu option. Essentially, you’re making gets read a string without words in it. The line you want to read is actually the next line. Using scanf instead of gets will fix it.

    Otherwise, your program is working as expected – it’s just that your functions don’t do anything yet that your menu is “overwriting” the submenus. See http://ideone.com/F2pEs for an implementation with scanf instead of gets.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My goal is to produce a program which can take a random number from
My goal is to produce a list of sortable elements that will be managed
Goal: Produce an Excel document with information from 3 associated models that is similar
The goal is to create a program which will effectively let the user create
I'm currently working on a program that analyses a wav file of a solo
My end goal is to produce a simple .deb package. For that I've read
I'm attempting to produce a widget that consists of a text display that can
My goal is to produce a table with two header rows. The first with
Goal is to make a dialog that appears on menu_key pressed, but it keeps
Goal I am building an Eclipse plugin targeting the 3.7 environment and would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.