Adding Another function

Warning 1 warning C4717: 'myStrCat' : recursive on all control paths, function will cause runtime stack overflow

I have the first Portion Correct, but somehow after myStrCat it doesn't compile.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  #include <iostream>
#include <cstring>

using namespace std;

int myStrCopy(char *, const char *);
int myStrCat(char *, const char *);

int main()
{

	char str1[20] = "Hello";
	char str2[20];

	myStrCopy(str2, str1);

	cout << str1;
	cout << endl;
	cout <<"Value of str2 is " << str2 << endl;
}
int myStrCopy(char *str1, const char *str2)
{
	int a = 0;

	while (str2[a] != '\0')
	{
		str1[a] = str2[a];
		a++;
	}
	str1[a] = '\0';
	return 0;
}
int myStrCat(char *, const char *)
{
	const int size = 20;
	char str1[20] = "Hello";
	char str2[20] = "World";

	cout << str1 << endl;
	cout << str2 << endl;
	myStrCat(str1, str2);
	cout << str1 << endl;
	return 0;

}


OutPut for myStrCopy

1
2
Hello
Value of str2 is Hello

Last edited on
please help
Why do you have line 41 in that function? It will just repeat an unlimited amount of times like the error says. What are you trying to achieve?

*edit
Also there are more returns types than just int. You should probably put void and not return anything since you arne't even using the value that is being returned. Most of the time when you pass by references or pointers and you modify the variables directly you will return void unless you are returning an error code but that doesn't seem to be the case.


Also you forgot to give parameter names on line 33.
Last edited on
i have to add another function called myStrCat with this
1
2
char str1[20] = "Hello";
char str2[20] = "World";
closed account (D80DSL3A)
The function myStrCat() will be very similar to the myStrCopy() function.
Look at lines 25-30 in myStrCopy
25
26
27
28
29
30
while (str2[a] != '\0')
{
	str1[a] = str2[a];
	a++;
}
str1[a] = '\0';

In myStrCat those lines should be:
1
2
3
4
5
6
while (str2[a] != '\0')
{
	str1[a+len1] = str2[a];
	a++;
}
str1[a+len1] = '\0';

Where len1 is the length of str1 before concatenation. A myStrLen() function would be handy for finding len1.
im still getting the same output. I know im doing something wrong but i cant seem to figure it out
Allows private messages in your account settings, i can send to you an explanation of a similar exercise.
i enabled pm
Topic archived. No new replies allowed.