Question
C++ Programming I have finished the code but there's one error which shows that strcpy might be unsafe. Consider using strcpy_s instead. I've tried that
C++ Programming
I have finished the code but there's one error which shows that "strcpy" might be unsafe. Consider using strcpy_s instead. I've tried that but it's not working probably because I didn't implement it correctly. I am posting my code below. It'd be really helpful if you could fix all the strcpy errors and post it below. Thank you.
Text.cpp:
#include
Text::Text ( const char *charSeq ) { bufferSize = strlen(charSeq) + 1; buffer = new char[bufferSize]; strcpy(buffer, charSeq); }
Text::Text ( const Text &other ) { bufferSize = other.bufferSize; buffer = new char[bufferSize]; strcpy(buffer, other.buffer); }
void Text::operator = ( const Text &other ) { int len = other.bufferSize; if (len > bufferSize) { delete[] buffer; bufferSize = other.bufferSize; buffer = new char[bufferSize]; } strcpy(buffer, other.buffer); }
Text::~Text () { delete[] buffer; }
int Text::getLength () const { return bufferSize - 1; }
char Text::operator [] ( int n ) const { // check if n is out of range first return 0; }
void Text::clear () { buffer[0] = '\0'; }
void Text::showStructure() const
// Outputs the characters in a string. This operation is intended for // testing/debugging purposes only.
{ int j; // Loop counter
for (j = 0; j < bufferSize; j++) cout << j << "\t"; cout << endl; for (j = 0; buffer[j] != '\0'; j++) cout << buffer[j] << "\t"; cout << "\\0" << endl; }
Text Text::toUpper( ) const { Text temp; for (int i = 0; i < bufferSize; i++) { if ((buffer[i] > 96 && (buffer[i] < 123))) { temp.buffer[i] = char(buffer[i] - 32); } } return temp; }
Text Text::toLower( ) const { Text temp; for (int i = 0; i < bufferSize; i++) { if ((buffer[i] > 64 && (buffer[i] < 91))) { temp.buffer[i] = char(buffer[i] + 32); } } return temp; }
bool Text::operator == ( const Text& other ) const { { if (bufferSize == other.getLength()) { if (bufferSize == 0) { return true; } else { for (int i = 0; i < bufferSize; i++) { if (buffer[i] != other.buffer[i]) { return false; } } return true; } } else { return false; } } }
bool Text::operator < ( const Text& other ) const { if (bufferSize < other.getLength()) { return true; } else { return false; } }
bool Text::operator > ( const Text& other ) const { if (bufferSize > other.getLength()) { return true; } else { return false; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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