Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started