- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <string.h>
- int main(void)
- {
- char str[1000] = "Hello, world"; // 輸入字串
- char str2[6] = "or";
- int result; // 比對結果
- int i;
- //scanf("%s", &str);
- result = strcmp ("hello", "hello");
- printf ("result:%d\n", result); //=> 0 These two strings are the same. */
- result = strcmp ("hello", "Hello");
- printf ("result:%d\n", result); //=> 1 Comparisons are case-sensitive. */
- result = strcmp ("hello", "world");
- printf ("result:%d\n", result); //=> -1 The character 'h' comes before 'w'. */
- result = strcmp ("hello", "hello, world");
- printf ("result:%d\n", result); //=> -1 Comparing a null character against a comma. */
- result = strncmp ("hello", "hello, world", 5);
- printf ("result:%d\n", result); //=> 0 The initial 5 characters are the same. */
- result = strncmp ("hello, world", "hello, stupid world!!!", 5);
- printf ("result:%d\n", result); //=> 0 The initial 5 characters are the same. */
- system("pause");
- return 0;
- }
複製代碼 利用result值可做目標搜尋... |