string class | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Respostas
+ 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