Array

I can't input an array, what's the problem here?

1
2
3
4
5
6
7
8
9
10
11
12
13
 void act2(){

	char string1[100], string2[100];

	cout << " Enter word: ";
	cin.getline(string1, 100);
	strcpy_s(string2, string1);
	cout << string2 << endl;
	cout << strcmp(string1, string2) << endl;
	if (string1 == string2)
		cout << string1;

}
You are using C++, so you should use C++ for strings too. (the std::string)


Line 10. The addresses of two different objects are never the same.
i added a newLine function between line 6 & 7. It lets me input a string but it outputs 0
I added using namespace std; at the top.

The program should let me input a string1.
And string1 should be equal to string 2 and i should output string 2.
Then, it should output 0 saying that string1 = string 2.
I fixed it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void act2()
{
	char string1[100], string2[100];

	cout << " Enter word: ";
	newLine();
	cin.getline(string1, 100);
	strncpy_s(string2, string1, 100);
	cout << string2 << endl;
	cout << strcmp(string1, string2) << endl;
	if (string1 == string2)
		cout << string1;

}
Do not use any *_s functions. They are not part of the standard and are mainly MS extension.
Topic archived. No new replies allowed.