Array and Char with function

Pages: 12
Hey everybody,

Updated version(11.01.2017)

I have to do something for Array() at Line 36

and

I have to do something for CharAt( ) Line 39

What is your advice? What should I do for Array() and Char( ) function with parameters in header Like Array()

Note: That will fulfill the unit test.
That is okey or not for charArray function?

Thanks


Last edited on
Can't you just pass m_str to my_len?
@Peter87 Do you think like this?

1
2
3
4
int String::length() 
{
	my_len(m_str);
}
Yes, but you also need to return the value.
Last edited on
@Peter87 How can i do?
By using the return keyword.

1
2
3
4
int String::length() 
{
	return my_len(m_str);
}
@Peter87 It doesn't work.
Yet another of these cryptic 'it doesn't work' messages. When will you guys realize that its not mind-readers on the other side? What doesn't work? What are the error messages? Where is you program????
@gunnerfunner My all codes in here and header and other codes in my question. I have to do something for TEST_TRUE

What is your advice?

Thanks
Last edited on
It's difficult to read snippets of code spread over various posts and most of it inaccurate, otherwise you wouldn't be here
@gunnerfunner I edited. You can check it now. Thanks.
Line 27 in main. To use std::strcpy you should include <cstring> (maybe you want to use the my_cpy function instead?).
#include <cstring>

Line 29 in main. malloc returns a void pointer so if you want to assign it to a char pointer you need to cast it.
char* str = static_cast<char*>(malloc(10));

If you want to be able to pass a string literal to the String constructor you need to make the parameter type a pointer to a const char. You'll also need to change the condition for the case when a null pointer is passed in because you can't assign a non-const char* to a const char*.
1
2
3
4
String::String(const char * other_str)
{
	m_str = (other_str ? my_strdup(other_str) : nullptr);
}
@Peter87 Thanks . I am using my_cpy function.

What is your advice for TEST_TRUE(string1.length() == 11);
What's the problem?
I have to do somethig for :

TEST_TRUE(string1.length() == 11);

and

1
2
3
4
5
int String::length() 
{
	return my_len();
}
Last edited on
I can only repeat what I said earlier.
1
2
3
4
int String::length() 
{
	return my_len(m_str);
}


After fixing the problems I pointed out the code compiles and seems to run just fine. If you still have problems you will have to tell us what they are. Do you get an error message? What is it? Is the output wrong? What do you get and what did you expect?
Now, I wrote

1
2
3
4
int String::length() 
{
	return my_len(m_str);
}



But I have to 2 errors.

1
2
3
Error	C2440	'initializing': cannot convert from 'void *' to 'char *'	       Line 56	

Error	C2440	'initializing': cannot convert from 'const char *' to 'String'	Line	60	

What's on line 56 and 60?
Hi, I updated the question.

Now problem on String string1 = hello_world_str;

Error:
C2440 'initializing': cannot convert from 'const char *' to 'String'

How can I solve this problem?
You should change the String constructor to accept a const char*. I mentioned this in an earlier post.
Pages: 12