c - strcmp 中未使用的表达式结果
问题描述
我正在尝试获取代码以将用户输入的字符串与用户的命令行字符串进行比较。我尝试了其他方法,我认为考虑到它的编码几乎相同,这会更容易,并且只是检查输入的字符串是否是以前的字符串之一,如果不是,它应该返回 false 但继续循环直到它检查了所有用户的命令行字符串。
bool vote(string name)
{
for (int i = 0; i < candidate_count; i++) //loop through all the candidates
{
if (strcmp(name, candidates[i].name) == 0) //this part works however alone it considers all user strings to be true that's why I added the other code to have it check if the users string does not exist and if so it would return false
{
candidates[i].votes++;
return true;
}
else (strcmp(name, candidates[i].name) != 0); //expression result unused?
{
return false;
}
}
return false;
}
当我告诉它在测试该字符串后返回循环时,我不明白为什么它会不使用表达式结果。我所拥有的应该是一次检查每个用户字符串,然后说出该人是否退出或者他们是否不存在并跳过该投票。
解决方案
你在行尾有一个错字。
else (strcmp(name, candidates[i].name) != 0); //expression result unused?
^^^
推荐阅读
- javascript - 通过 datepicker 获取 url 并刷新
- python - 真实与预测图散点图
- python - 使用另一个数据帧更改 Pandas 数据帧中的列中的值
- angular - 在 PrimeNG 表中过滤后自定义排序不起作用
- javascript - 如何知道javascript中的CPU使用率?
- ruby-on-rails - graphql-ruby 基于连接的分页如何影响 ActiveRecord 查询?
- algorithm - 图上 DFS 的时间复杂度 (O(V+E)) 与矩阵上的 DFS (3^(M*N))
- phpstorm - JetBrains IDE - 如何在“Alt+Shift+Enter”之后删除选择
- gstreamer - 在 C 应用程序中使用合成器
- python-3.x - python网络爬虫,响应[403]