Program to Compare Two Strings Without using strcmp ()

Whenever we are asked to write a program to compare two strings, we make use of inbuilt function- strcmp (). Obviously, it is the easy method and we can use that. But sometimes, we are asked not to use the strcmp (). This program helps to compare two strings without using strcmp ()



Void main()


char string1[5],string2[5];

int i,temp = 0;

printf(“Enter the  1st string :\n”);


printf(“\n Enter the 2nd String :\n”);


for(i=0; string1[i]!=’\0′; i++)


if(string1[i] == string2[i])

temp = 1;


temp = 0;


if(temp == 1)

printf(“Both the strings entered  are same.”);


printf(“Both the strings entered are not same.”);



Mohit Arora
Follow me