المتغيرات
فضاءات التسمية
أفعال

strcmp

من cppreference.com
< c‏ | string‏ | byte
معرفة في ملف <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.

[تعديل] أنظر أيضا

تقارن بين عدد معين من حروف سلسلتين نصيتين
(دالة) [edit]
تقارن بين مصفوفتين
(دالة) [edit]
تقارن بين سلسلتين نصيتين طبقا للإعداد المحلي الحالي
(دالة) [edit]