C: How to compare two strings? [duplicate]

▼魔方 西西 提交于 2019-12-02 00:47:18

You need to use strncmp to compare strings:

if (strncmp(record.fields[2], "1", 1) == 0) ...

You need to compare to zero, because strcmp returns zero when two strings are identical.

However, it looks like you are not comparing strings: rather, you are looking for a specific character inside the string. In this case, you need to use a character constant instead of a string literal (with single quotes):

if (record.fields[2] == '1') ...
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!