forked from Romeo-Aryal/C-program-fest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stringComapre.c
42 lines (42 loc) · 1.17 KB
/
stringComapre.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
// C program to compare the two strings
// without using strcmp() function
#include <stdio.h>
#define str_size 100 //Declare the maximum size of the string
int test(char* s1, char* s2)
{
int flag = 0;
while (*s1 != '\0' || *s2 != '\0') {
if (*s1 == *s2) {
s1++;
s2++;
}
else if ((*s1 == '\0' && *s2 != '\0')
|| (*s1 != '\0' && *s2 == '\0')
|| *s1 != *s2) {
flag = 1;
break;
}
}
return flag;
}
int main(void)
{
char str1[str_size], str2[str_size];
int flg=0;
printf("\nInput the 1st string : ");
fgets(str1, sizeof str1, stdin);
printf("Input the 2nd string : ");
fgets(str2, sizeof str2, stdin);
printf("\nString1: %s", str1);
printf("String2: %s", str2);
flg = test(str1, str2);
if(flg == 0)
{
printf("\nStrings are equal.\n");
}
else if(flg == 1)
{
printf("\nStrings are not equal.");
}
return 0;
}