C Program to compare arrays


This content was proof-read by Grammarly. You can Try Grammary for FREE

Problem Statement

You need to write a program in C to compare two arrays of characters and display if they are equal or not.

How to compare two arrays in C ?

#include <stdio.h> 
#include <string.h> 
int main() 
{ 
     char arr1[35], arr2[35]; 
     printf("Please enter the 1st string\n"); 
     gets(arr1); 
     printf("Please enter the 2nd string\n"); 
     gets(arr2); 
    
     printf("Entered strings are\narr1 = %s \narr2 = %s", arr1, arr2); 
  
     if( strcmp(arr1,arr2) == 0 ) 
          printf("\nEntered strings are equal.\n"); 
     else 
          printf("\nEntered strings are not equal.\n"); 
     return 0; 
}
Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: