last program

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
//String Function with Pointer
//Micah Standing

#include <iostream>
using namespace std;

void strcpy(char st1[], char st2[]);
char strcat(char st3[], char st4[]);
int main()
{
	char *st1 = "Thomas Jefferson";
	char *st2 = "George Washington";
	char *st3 = "How are ";
	char *st4 = "you doing ? ";

	cout << "String 1 is " << st1 << endl;
	cout << "String 2 is " << st2 << endl;
}
void strcpy(char *st1, char *st2)
{
	int x;
	for(x = 0; (st1 + x) != 0; x++)
		st1 = st2;
		st1 = 0;	
}
char strcat(char *st3, char *st4)
{
	strcat(st3, st4);
	cout << "\nNow String 3 says " << st4 << endl;
	cout << "\n" << endl;
	return 0;
}

i got to use pointers with strcpy and strcat function and use it to copy something and concat something, apparently i got it right because there is no errors, but i can't get an output.
here is a warning i get:
strngfunc.cpp(32) : warning C4717: 'stcat' : recursive on all control paths, function will cause runtime stack overflow
what do i need to change.
You have overloaded the C library's strcat function with your own.
I think you intended your strcat function to call the library strcat() function.
If that is the case, change the name of your strcat function to something
else.
what do u mean by changing the name. do i change the strcat or something else. what do u mean i overloaded strcat function with my own. are you talking about the:
1
2
3
4
strcat(st3, st4);
	cout << "\nNow String 3 says " << st4 << endl;
	cout << "\n" << endl;
	return 0;

if you are how do i change it to the library strcat()function
Last edited on
What jsmith is saying is that you make your own function called strcat. Since there is already a function in the library with that name, the compiler assumes you are "overloading" the function. Therefore, when you call strcat inside of itself it is considered an infinite loop. Change your strcat function's name to something else.
so on the strcat function i got the char right or do i change it to a double or void or what.
i tried different names to call it but it is giving me the same warning message. i need an answer quick cause i got a final test at 2:00 so i need to turn this in to the teacher before the test.
Last edited on
Topic archived. No new replies allowed.