C++ examples for Data Type:char array
Using memcmp to compare the specified number of characters
#include <iostream> #include <iomanip> #include <cstring> // memcmp prototype using namespace std; int main() //from ww w . ja v a 2 s . c o m { char s1[] = "ABCDEFG"; char s2[] = "ABCDXYZ" ; cout << "s1 = " << s1 << "\ns2 = " << s2 << endl << "\nmemcmp(s1, s2, 4) = " << setw( 3 ) << memcmp( s1, s2, 4 ) << "\nmemcmp(s1, s2, 7) = " << setw( 3 ) << memcmp( s1, s2, 7 ) << "\nmemcmp(s2, s1, 7) = " << setw( 3 ) << memcmp( s2, s1, 7 ) << endl; }