Cho hai chuỗi str1 và str2, kiểm tra xem chúng có giống hệt nhau hay không (phân biệt chữ hoa/thường).
Hàm strcmp() trong string.h trả về 0 nếu hai chuỗi giống nhau.
Ví dụ
Input: "Hello", "Hello" → Output: Yes, 2 strings are same Input: "world", "World" → Output: No, 2 strings are not same
Mã nguồn C
#include <stdio.h>
#include <string.h>
int main() {
char string1[] = "tutorials point";
char string2[] = "tutorials point";
if (strcmp(string1, string2) == 0)
printf("Yes, 2 strings are same\n");
else
printf("No, 2 strings are not same\n");
return 0;
}
Kết quả
Yes, 2 strings are same