Skip to content

Commit a31de44

Browse files
committed
comparing strings
1 parent 9712df4 commit a31de44

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

prog.10.4.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

0 commit comments

Comments
 (0)