C program to compare two strings without using string functionsThis is String comparing program using c. In which we compare two without using any predefined function.
We take two string value and compare these strings using the index value of each string.
For Example:
string1= hello and string2= hello
there is both string is form of array. now we will compare the index value of both string and check weather is it is equal or not?
ALGORITHM:-
step 1 : start
step 2 : Take two char array
step 3 : Input the string value in both array from user
step 4 : Compare the [0]th zero index content of both array value until '\0'
step 5 : If [i]th values are not match of both array then return both are not equal
step 6 : If [i]th values are match of both array then return both are equal
step 7 : Exit
PROGRAM CODE:-
#include<stdio.h>
#include<stdio.h>
int comp(char[],char[]);
int main()
{
char string1[100],string2[100];
int c;
printf("Enter first string in array: ");
scanf("%s",string1);
printf("Enter second string in array: ");
scanf("%s",string2);
c = comp(string1,string2);
if(c == 1)
{
printf("Both are equal");
}
else
{
printf("Both are not equal");
}
return 0;
}
int comp(char string1[],char string2[])
{
int i=0,temp=0;
while(string1[i]!='\0' && string2[i]!='\0')
{
if(string1[i]!=string2[i])
{
temp=1;
break;
}
i++;
}
if(temp==0 && string1[i]=='\0' && string2[i]=='\0')
{
return 1;
}
else
{
return 0;
}
}
OUTPUT:-
Sample output:
Enter first string in array :- cprogrammingsimply
Enter second string in array :- cprogrammingsimply
Both are equal
C program to compare two string without using any funtion Compare two string in c without predefined function String comparison without any predefined function in c
ConversionConversion EmoticonEmoticon