Please can anyone help me on strlen, strcmp , strcpy, strcat...

May 24, 2015 at 8:43pm
I Edited my question

1. This is what i have and one below is testing code
1
2
3
4
5
6
7
8
9
10
11
int mystrlen(const char *s)
{
	int x=0; 
	for (int i = 0; i < 100; i++)
	{
		if (s[i] != '\0')
			x++; 
	}
	
	return x;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
void testmystrlen(void)
{
	size_t uiResult;

	uiResult = mystrlen("Ruth");
	ASSURE(uiResult == 4);

	uiResult = mystrlen("Gehrig");
	ASSURE(uiResult == 6);

	uiResult = mystrlen("");
	ASSURE(uiResult == 0);
}

I can't use s.size() since its address which is why I get bigger number than 20
for ruth and ""
is there way to fix this?
Last edited on May 24, 2015 at 9:56pm
May 24, 2015 at 9:44pm
Have you looked at the definitions of those functions?

Why do your versions stop at 100 comparisons?
May 24, 2015 at 9:49pm
testing my own let me edit my thing... i didn't know there was test cpp file ...
and i am suppose to create my own...
and yes I did look at definition which I really don't get
Last edited on May 24, 2015 at 9:51pm
May 24, 2015 at 10:37pm
NVM got it
May 24, 2015 at 10:39pm
and yes I did look at definition which I really don't get
Well, you have to get it if you are to reproduce their functionality.

What is it you didn't understand?
May 25, 2015 at 1:30am
Haha,, if i get it would I even post this in the first place?
Topic archived. No new replies allowed.