strcmp
من cppreference.com
<tbody>
</tbody>
| معرفة في ملف <string.h>
|
||
int strcmp( const char *lhs, const char *rhs ); |
||
تقوم بمقارنة متسلسلتين منتهيتين بـ '\0'. المقارنة تتم بالطريقة الألفبائية بحسب الأوائل.
المعطيات
| lhs, rhs | - | مؤشران الى مصفوفتين من البايت منتهيتان بـ '\0'
|
القيمة المُرجعة
قيمة سالبة في حالة أن lhs أصغر من rhs.
0 في حالة أن lhs تساوي rhs.
قيمة موجبة في حالة أن lhs أكبر من rhs.
مثال
قم بتشغيل هذا الكود:
#include <string.h>
#include <stdio.h>
int main(void)
{
const char* string = "Hello World!";
// مطابق
int a = strcmp(string, "Hello World!");
if (a == 0) {
printf("Strings are matching.\n");
}
//أكبر من
int b = strcmp(string, "Hello");
if (b >= 1) {
printf("Left hand side is bigger than right hand side.\n");
}
//أصغر من
int c = strcmp(string, "Hello there world!");
if (c <= -1) {
printf("Left hand side is smaller than right hand side.\n");
}
}
الخرج:
Strings are matching.
Left hand side is bigger than right hand side.
Left hand side is smaller than right hand side.
أنظر أيضا
| تقارن بين عدد معين من حروف سلسلتين نصيتين (دالة) | |
| تقارن بين مصفوفتين (دالة) | |
| تقارن بين سلسلتين نصيتين طبقا للإعداد المحلي الحالي (دالة) | |
مقالة مرجع C++ عن strcmp
| |