Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Working on C + + in a VS 2 0 2 2 environment and getting warning in the code below. warning C 4 9 9

Working on C++ in a VS 2022 environment and getting warning in the code below.
warning C4996: strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation.
warning C4996: 'strtok': This function or variable may be unsafe. Consider using strtok_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
#include "SortStrings.h"
void ReorderAlphabetical(const char * const inString, char * const outString )
{
size_t len = strlen(inString);
char* buff =(char*)calloc((len +1)*2, sizeof(char));
char* buff2= buff + len +1;
strcpy(buff, inString);
char* token = strtok(buff,"");
std::vector tokenList(10);
size_t i =0;
while (token){
tokenList[i]= token;
i++;
token = strtok(NULL,"");
}
size_t size = i;
i =0;
for (i =0; i < size -1; i++)
{
for (size_t j =1; j < size - i; j++)
{
if (strcmp(tokenList[j -1], tokenList[j])>0)
{
char* tmp = tokenList[j];
tokenList[j]= tokenList[j -1];
tokenList[j -1]= tmp;
}
}
}
for (i =0; i < size; i++)
{
printf("%s
", tokenList[i]);
strcat(buff2, tokenList[i]);
if (i != size -1)
{
strcat(buff2,"");
}
}
strcpy(outString, buff2);
free(buff);
}
void ReorderWordLength(const char * const inString, char * const outString )
{
size_t len = strlen(inString);
char* buff =(char*)calloc((len +1)*2, sizeof(char));
char* buff2= buff + len +1;
strcpy(buff, inString);
char* token = strtok(buff,"");
std::vector tokenList(10);
size_t i =0;
while (token){
tokenList[i]= token;
i++;
token = strtok(NULL,"");
}
size_t size = i;
i =0;
for (i =0; i < size -1; i++)
{
for (size_t j =1; j < size - i; j++)
{
if (
(strlen(tokenList[j -1])> strlen(tokenList[j]))||
((strlen(tokenList[j -1])== strlen(tokenList[j])) && (strcmp(tokenList[j -1], tokenList[j])>0)))
{
char* tmp = tokenList[j];
tokenList[j]= tokenList[j -1];
tokenList[j -1]= tmp;
}
}
}
for (i =0; i < size; i++)
{
printf("%s
", tokenList[i]);
strcat(buff2, tokenList[i]);
if (i != size -1)
{
strcat(buff2,"");
}
}
strcpy(outString, buff2);
free(buff);
}
//--- End of File ---
I think I need to change strcpy, strtok, and strcat to strcpy_s, strtok_s, and strcat_s. Please change it.
Please do not change the code structure or warning suppress.

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 Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

Students also viewed these Databases questions

Question

Are there any questions that you want to ask?

Answered: 1 week ago