Skip to content

更新字符串示例 #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/string.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,13 @@ int strcmp(const char* s1, const char* s2);
下面是一个用法示例。

```c
// s1 = Happy New Year
// s2 = Happy New Year
// s3 = Happy Holidays
char* s1 = "Happy New Year";
char* s2 = "Happy New Year";
char* s3 = "Happy Holidays";

strcmp(s1, s2) // 0
strcmp(s1, s3) // 大于 0
strcmp(s3, s1) // 小于 0
printf("%d\n",strcmp(s1, s2));// 0
printf("%d\n",strcmp(s1, s3)); // 大于 0
printf("%d\n",strcmp(s3, s1)); // 小于 0
```

注意,`strcmp()`只用来比较字符串,不用来比较字符。因为字符就是小整数,直接用相等运算符(`==`)就能比较。所以,不要把字符类型(`char`)的值,放入`strcmp()`当作参数。
Expand Down