Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

How to compare two strings in c without using strcmp ?

 How to compare two strings in c without using strcmp ?  
 #include <stdio.h>  
 #include <stdlib.h>  
 int main()  
 {  
   char s1[5],s2[5];  
 int i,temp = 0;  
 printf("Enter the string1 value:\n");  
 gets(s1);  
 printf("\nEnter the String2 value:\n");  
 gets(s2);  
 for(i=0; (s1[i]!='\0')||(s2[i]!='\0'); i++)  
 {  
 if(s1[i] != s2[i])  
 {  
 temp = 1;  
 break;  
 }  
 }  
 if(temp == 0)  
 printf("Both strings are same.");  
 else  
 printf("Both strings not same.");  
   return 0;  
 } 

 

Post a Comment

0 Comments