/* StringEquality.c (c) Kari Laitinen http://www.naturalprogramming.com/ 2013-11-24 File created. 2013-11-24 Last modification. */ #include #include int main() { char first_c_style_string[] = "xxxxxx" ; char second_c_style_string[] = "yyyyyy" ; printf( "\n %s %s", first_c_style_string, second_c_style_string ) ; if ( strcmp( first_c_style_string, second_c_style_string ) == 0 ) { printf( "\n Equal C-style strings." ) ; } else { printf( "\n Not equal C-style strings." ) ; } if ( first_c_style_string == second_c_style_string ) { printf( "\n The same C-style strings were compared." ) ; } else { printf( "\n Different C-style strings were compared." ) ; } strcpy( second_c_style_string, first_c_style_string ) ; printf( "\n %s %s", first_c_style_string, second_c_style_string ) ; if ( strcmp( first_c_style_string, second_c_style_string ) == 0 ) { printf( "\n Equal C-style strings." ) ; } else { printf( "\n Not equal C-style strings." ) ; } if ( first_c_style_string == second_c_style_string ) { printf( "\n The same C-style strings were compared." ) ; } else { printf( "\n Different C-style strings were compared." ) ; } char* first_string_to_compare = (char*) first_c_style_string ; char* second_string_to_compare = (char*) first_c_style_string ; printf( "\n %s %s", first_string_to_compare, second_string_to_compare ) ; if ( strcmp( first_string_to_compare, second_string_to_compare ) == 0 ) { printf( "\n Equal C-style strings." ) ; } else { printf( "\n Not equal C-style strings." ) ; } if ( first_string_to_compare == second_string_to_compare ) { printf( "\n The same C-style strings were compared." ) ; } else { printf( "\n Different C-style strings were compared." ) ; } printf( "\n" ) ; }