File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Function to determine if two strings are equal
2
+
3
+ #include <stdio.h>
4
+ #include <stdbool.h>
5
+
6
+ bool equalStrings (const char s1 [], const char s2 [])
7
+ {
8
+ int i = 0 ;
9
+ bool areEqual ;
10
+
11
+ while ( s1 [i ] == s2 [i ] &&
12
+ s1 [i ] != '\0' && s2 [i ] != '\0' )
13
+ ++ i ;
14
+
15
+ if ( s1 [i ] == '\0' && s2 [i ] == '\0' )
16
+ areEqual = true;
17
+ else
18
+ areEqual = false;
19
+
20
+ return areEqual ;
21
+ }
22
+
23
+ int main (void )
24
+ {
25
+ bool equalStrings (const char s1 [], const char s2 []);
26
+ const char stra [] = "string compare test" ;
27
+ const char strb [] = "string" ;
28
+
29
+ printf ("%i\n" , equalStrings (stra , strb ));
30
+ printf ("%i\n" , equalStrings (stra , stra ));
31
+ printf ("%i\n" , equalStrings (strb , "string" ));
32
+
33
+ return 0 ;
34
+ }
You can’t perform that action at this time.
0 commit comments