The issue is in the picture: When I input the the name of the file after choosing option (e) in the main menu, I enter the file name and purposefully enter it wrong (I enter hello.txt). The code then brings me back to the main menu where I press option (e) again. I then enter the correct name of the file (which is letters.txt) and the program continues. The program then asks me to input the name of the new file, and then I put new.txt, but the problem begins here. The program then asks me again to input the name of the new file (but it should only do it once).
The issue is in the picture: When I input the the name of the file after choosing option (e) in the main menu, I enter the file name and purposefully enter it wrong (I enter hello.txt). The code then brings me back to the main menu where I press option (e) again. I then enter the correct name of the file (which is letters.txt) and the program continues. The program then asks me to input the name of the new file, and then I put new.txt, but the problem begins here. The program then asks me again to input the name of the new file (but it should only do it once).
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Why doesn't this work?
The issue is in the picture:
When I input the the name of the file after choosing option (e) in the main menu, I enter the file name and purposefully enter it wrong (I enter hello.txt). The code then brings me back to the main menu where I press option (e) again. I then enter the correct name of the file (which is letters.txt) and the program continues. The program then asks me to input the name of the new file, and then I put new.txt, but the problem begins here. The program then asks me again to input the name of the new file (but it should only do it once).
------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100
void main_menu();
void menu_helper_function(char my_file[], char new_file[]);
int main()
{
main_menu();
}
void main_menu()
{
intstatus;
charuser_input;
charencrypt_file_name[MAX],new_encrypt_file_name[MAX];
chardecrypt_file_name[MAX],new_decrypt_file_name[MAX];
do
{
status=0;
printf("Enter one of the following options:\n");
printf("(e)Encrypt a File\n(d)Decrypt a File\n(q)Quit\n");
user_input=getchar();
getchar();
if (user_input=='e')
{
menu_helper_function(encrypt_file_name,new_encrypt_file_name);
status=1;
}
elseif (user_input=='d')
{
menu_helper_function(decrypt_file_name,new_decrypt_file_name);
status=1;
}
elseif (user_input=='q')
{
printf("Thanks and bye!\n");
exit(1);
}
} while(status == 0);
}
void menu_helper_function(char my_file[], char new_file[])
{
FILE*fp_in,*fp_out;
printf("Enter the name of your file:\n");
fgets(my_file,MAX,stdin);
/* Remove newline, if applicable */
if (my_file[strlen(my_file)-1] =='\n')
my_file[strlen(my_file)-1] ='\0';
fp_in=fopen(my_file,"r");
if (fp_in==NULL)
{
printf("Couldn't open the file\n");
main_menu();
}
printf("Enter the name of your new file:\n");
fgets(new_file,MAX,stdin);
/* Remove newline, if applicable */
if (new_file[strlen(new_file)-1] =='\n')
new_file[strlen(new_file)-1] ='\0';
fp_out=fopen(new_file,"w");
if (fp_out==NULL)
{
printf("Couldn't open the file\n");
main_menu();
}
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 1 images
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY