0

string class

the code is: https://code.sololearn.com/ca19a22A1697 problem: I want to pass a string with the size from the main function but don't know how.Can someone show me how I can do it.

4th May 2021, 9:04 AM
Ramisa Fariha
Ramisa Fariha - avatar
5 odpowiedzi
+ 1
Not sure what you want to do, but the implementation of String(const char*) is wrong because len is undefined. You can get the len with the following: len = 0; const char* p = str; while(*p++) ++len; You can also initialize your data in the loop and remove the memcpy() if you want. This way, the calling of String("Text") will Initialize data and len correctly.
4th May 2021, 9:32 AM
你知道規則,我也是
你知道規則,我也是 - avatar
4th May 2021, 12:13 PM
Flash
+ 1
@Martin Thanks a trillion ...
4th May 2021, 12:17 PM
Ramisa Fariha
Ramisa Fariha - avatar
0
The question given was: 10.6 Implement a String class. Each object of this class will represent a character string. Data members are the length of the string and the actual character string. In addition to constructors, destructor, access functions, and a print function, include a “subscript” function.
4th May 2021, 9:04 AM
Ramisa Fariha
Ramisa Fariha - avatar
0
@Flash Thanks a lot
4th May 2021, 12:18 PM
Ramisa Fariha
Ramisa Fariha - avatar