Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I use a more secure way of using prinf according to MSC24-C. Do not use deprecated or obsolescent functions in the below C

How do I use a more secure way of using prinf according to MSC24-C. Do not use deprecated or obsolescent functions in the below C code example. Please change all the fprinf to a more secure function and provide a screen shot of it working?

#include

#include

// Function prototypes void fillPassword(size_t , char[]); void showResults(char); void printf_s_l();

// should have void listed void showMenu();

// Define a variable to hold a password // and the copy char password[15]; char cpassword[15]; int main(void)

{ // Welcome the User printf_s_l("Welcome to the C Array Program! ");

// Variables char cont = 'y'; // To continue with loop int cVar = 0; // process variable

// Display menu and Get Selection while (1)

{ // Display the Menu showMenu();

scanf("%c", &cont);

// Display the menu response showResults(cont);

// if user wants to exit if( cont == 'e' || cont == 'E' )

break;

// to get the next line character scanf("%c", &cont);

}

// Call the Copy routine fillPassword(sizeof(password),password);

// Display variable values printf("password is %s ", password); printf("cVar is %d ", cVar);

// Copy password memcpy(cpassword, password,sizeof(password));

// Pause before exiting char confirm;

printf("Confirm your exit!");

confirm = getchar();

return 0;

}

// Make a String of '1's void fillPassword(size_t n, char dest[]) { // Should be n-1 for (size_t j = 0; j < n; j++) { dest[j] = '1'; } // Add null terminator for string dest[n] = '\0'; }

/* Display the Results*/ void showResults(char value) {

switch (value){

case 'F': printf("Welcome to the Football season! "); break;

case 'f': printf("Welcome to the Football season! "); break;

case 'S': printf("Welcome to the Soccer season! "); break;

case 's': printf("Welcome to the Soccer season! "); break;

case 'B': printf("Welcome to the Baseball season! ");

break;

case 'b': printf("Welcome to the Baseball season! "); break;

case 'E': printf("Exiting the Menu system! "); break;

case 'e': printf("Exiting the Menu system! "); break;

default: printf("Please enter a valid selection ");

}

}

/* Display the Menu*/ void showMenu(void) {

printf("Enter a selection from the following menu. ");

printf("B. Baseball season. ");

printf("F. Football season. ");

printf("S. Soccer season. ");

printf("E. Exit the system. ");

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions