-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompare_two_strings.c
51 lines (45 loc) · 947 Bytes
/
compare_two_strings.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//wap to compare two string
#include<stdio.h>
int string_length(char *n);
int compare(char *a,int length_one,char *b,int length_two);
int main()
{
char a[10],b[10];
int length_one,length_two,result;
printf("enter first string\n");
scanf("%s",a);
printf("enter second string\n");
scanf("%s",b);
//find the length of two strings
length_one=string_length(a);
length_two=string_length(b);
//compare two strings
result=compare(a,length_one,b,length_two);
if(result==1)
printf("%s and %s are same\n",a,b);
else
printf("%s and %s are different\n",a,b);
}
//length of string find using function
int string_length(char *n)
{
int count=0,i;
for(i=0;i<'\0';i++)
count++;
return count;
}
//compare two strings here
int compare(char *a,int length_one,char *b,int length_two)
{
int i,j,count=0;
if(length_one==length_two)
{
for(i=0;i<'\0';i++)
{
if(*(a+i)==*(b+i))
count++;
}
}
if(count==length_one)
return 1;
}