InterviewSolution
| 1. |
How Do I Compare Character Data Stored At Two Different Memory Locations? |
|
Answer» Sometimes in a program we REQUIRE to COMPARE memory ranges containing strings. In such a situation we can use functions like memcmp ( ) or memicmp ( ). The basic DIFFERENCE between two functions is that memcmp ( ) does a case-sensitive comparison whereas memicmp ( ) ignores case of characters. Following program illustrates the use of both the functions. #include main( ) { char *arr1 = Kicit ; char *arr2 = kicitNagpur ; c = memcmp ( arr1, arr2, sizeof ( arr1 ) ) ; if ( c == 0 ) printf ( Strings arr1 and arr2 compared using memcmp are identical ) ; else printf ( Strings arr1 and arr2 compared using memcmp are not identical ) ; c = memicmp ( arr1, arr2, sizeof ( arr1 ) ) ; if ( c == 0 ) printf ( Strings arr1 and arr2 compared using memicmp are identical ) ; else printf ( Strings arr1 and arr2 compared using memicmp are not identical ) ; } Sometimes in a program we require to compare memory ranges containing strings. In such a situation we can use functions like memcmp ( ) or memicmp ( ). The basic difference between two functions is that memcmp ( ) does a case-sensitive comparison whereas memicmp ( ) ignores case of characters. Following program illustrates the use of both the functions. #include main( ) { char *arr1 = Kicit ; char *arr2 = kicitNagpur ; int c ; c = memcmp ( arr1, arr2, sizeof ( arr1 ) ) ; if ( c == 0 ) printf ( Strings arr1 and arr2 compared using memcmp are identical ) ; else printf ( Strings arr1 and arr2 compared using memcmp are not identical ) ; c = memicmp ( arr1, arr2, sizeof ( arr1 ) ) ; if ( c == 0 ) printf ( Strings arr1 and arr2 compared using memicmp are identical ) ; else printf ( Strings arr1 and arr2 compared using memicmp are not identical ) ; } |
|