Comparing strings - beginner question
So I've just started out programming more or less and have run into trouble. I'm going through the c++ tutorial on the site and so far doing pretty well I believe. I've tried searching about the web for a reason for the problem stated below, but have come up empty handed - mainly I suspect because of an inability to phrase my question right as my programming vocabulary I still sadly lacking.
I'll work around the problem for now, but this is the first thing I just plain don't understand - and I'd like to. Any help is greatly appreciated.
Why does this work;
Code:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char a[2], c[2], b[2], asdf = 'A';
if (strcmp (a, c) + strcmp (a, c) == 2) {
cout << "They're all the same.";
cin.get();
}
else {
cout << "They're not the same. Silly C++ - they actually are.";
cin.get();
}
}
While this returns error "array must be initialised with brace-enclosed initializor"?
Code:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char a[2], c[2], b[2] = 'A';
if (strcmp (a, c) + strcmp (a, c) == 2) {
cout << "They're all the same.";
cin.get();
}
else {
cout << "They're not the same. Silly C++ - they actually are.";
cin.get();
}
}
Note all I've done is remove the not-used asdf variable. I really don't get this, but I'll work around it in the cmd Tic Tac Toe program I'm trying to create.
Thanks a lot for your time - I hope I'm not unknowingly breaking any forum rules, but if I am I'd like help in keeping with them as well. The site so far has been by far the best resource for learning for me a complete beginner. Thanks!
EDIT; The above is just a test-program for me to try out theories and principles in. It's not part of the actual program I'm trying to create - merely me trying to understand a concept.