Hello friends!!!!!

To compare first 'n' characters of the strings

C LANGUAGE

11/20/20241 min read

// To compare first 'n' strings

#include <stdio.h>

#include<string.h>

int main() {

char a[50] = "Rishendra";

char b[50] = "Rishi";

// strncmp - To compare the "n" characters of two strings given

if(strncmp(a , b, 4) == 0) {

printf("First 4 characters of both strings are equal");

}

else{

printf("Both are not same");

}

}

Output:

First 4 characters of both strings are equal

=== Code Execution Successful ===