![C program to compare two strings without using strcmp() C program to compare two strings without using strcmp()](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2xTdzAQ9icoX1DuLjsE3r078zd0cXxUSzW2gir9vs5wzQ_w6Wij5jVEsL6oQ8txGeYHCexmj4Tj7YIj5b3MXmVs2VgKDmiHTmH5Yk2BB5Fcat9sIAPFadpSaw1EUMuQsPIi3rIS-_d3Qb/s640/C+program+to+compare+two+strings+without+using+strcmp%2528%2529.jpg)
Program:
#include<stdio.h>
#include<conio.h>
/* c program to compare two strings without using strcmp() by SlashMyCode.com */
int main()
{
char str1[20], str2[20];
int i;
printf("Enter 1st string : ");
gets(str1);
printf("\nEnter 2nd string : ");
gets(str2);
i = 0;
while (str1[i] == str2[i] && str1[i] != '\0')
i++; /* incrementing i since we want to check next element in string */
if (str1[i] > str2[i])
printf("str1 > str2");
else if (str1[i] < str2[i])
printf("str1 < str2");
else
printf("str1 = str2");
/* c program to compare two strings without using strcmp() by SlashMyCode.com */
getch();
}
Output:
![output of C program to compare two strings without using strcmp output of C program to compare two strings without using strcmp](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiD0JynrqpJsYq_HJLfgsjK3bU6ARJO8b8nTdyfRUB2LsyeddG9alf9sQLxkSXCoGxc1JPtzOwr5SIFQmub3vgrrCdsQngq2gDGTa9_T4EazZQFYP5yVKDrmKq-hL7xzf_5OQOBpru4oBt3/s640/Output+of+C+program+to+compare+two+strings+without+using+strcmp%2528%2529.jpg)
Flowchart:
No comments:
Post a Comment
Feel free to ask us any question regarding this post