Can I do...
Code:char first[10] = "123456789"; char second[10] = "123456789"; if (first == second) { printf("The strings are the same"); } else { printf("The strings are not the same"); }
This is a discussion on string equality testing within the C Programming forums, part of the General Programming Boards category; Can I do... Code: char first[10] = "123456789"; char second[10] = "123456789"; if (first == second) { printf("The strings are ...
Can I do...
Code:char first[10] = "123456789"; char second[10] = "123456789"; if (first == second) { printf("The strings are the same"); } else { printf("The strings are not the same"); }
Yes, but you actually want to use say, strcmp().
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
In the context you've mentioned above, the expression testing for equality is actually comparing the address of the two variables ("first" and "second"). The address of these two distinct variables will never be the same. In C++ using std::string containers you can test the variables as you've done but in C you need the strcmp function.
I used to be an adventurer like you... then I took an arrow to the knee.