Skip to content

Commit 42137df

Browse files
committed
Use macro in Contains() instead of func
#define Contains(str,substr) ((_Bool)strstr((str), (substr)))
1 parent bd6aba7 commit 42137df

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

‎c/String/gostring.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,7 @@ void testCount()
181181
printf("Count(\"%s\",\"%s\")=%d\n", s1, s2, Count(s1, s2));
182182
printf("Count(\"%s\",\"%s\")=%d\n", s1, s3, Count(s1, s3));
183183
}
184-
_Bool Contains(const char *str, const char *substr)
185-
{
186-
return (_Bool)strstr(str, substr);
187-
}
184+
#define Contains(str, substr) ((_Bool)strstr((str), (substr)))
188185

189186
void testContains()
190187
{
@@ -201,6 +198,8 @@ void testContains()
201198
printf("Contains(\"%s\",\"%s\")=%d\n", s1, s5, Contains(s1, s5));
202199
printf("Contains(\"%s\",\"%s\")=%d\n", s1, s6, Contains(s1, s6));
203200
printf("Contains(\"%s\",\"%s\")=%d\n", s1, s7, Contains(s1, s7));
201+
printf("Contains(\"%s\",\"%s\")=%d\n", "", "", Contains("", ""));
202+
printf("Contains(\"%s\",\"%s\")=%d\n", "1", "", Contains("1", ""));
204203
}
205204

206205
int main()
@@ -211,5 +210,5 @@ int main()
211210
// testToUpper();
212211
// testToLower();
213212
// testCount();
214-
// testContains();
213+
testContains();
215214
}

0 commit comments

Comments
 (0)