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"?
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.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(); } }
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.



LinkBack URL
About LinkBacks



Thanks for the input. The goal for me is trying to find a way to identify when a player has got three in a row. The methods I've tried either result in nothing happening or whoever finishes a sequence involving either X or O's or a mix thereof get's credit. It's anonnoying the hell out of me - enough that I think it might be too advanced and that I should return to this later. I know finishing this would make my software-engineer-dad extremely proud though (as I work in a completely unrelated field).This was posted as a solution to a similar issue;