c - 如何从字符串中获取字符
问题描述
我可以问为什么它显示“零”而不是索引吗?
电流输出:0
预期输出:6
#include<stdio.h>
#include<stdlib.h>
int main() {
int index_equal;
char array[20] = {"2n+n2n=n4n"};
for (int j = 0; j > 20; j++) {
if (array[j] == '=') {
index_equal = j;
}
}
printf("\n%d", index_equal);
}
解决方案
for 循环有问题你应该写 j<20 否则循环将永远不会执行
for(int j=0;j<20;j++)
这应该是正确的方法
推荐阅读
- python - 如何检查 Pandas DataFrame 中是否有任何值是 NaN(numpy.float64 类型)
- apache-spark - Spark的StructField对象的元数据属性是什么
- typescript - Typegoose 和 NestJS:类型上不存在属性“保存”
- php - 如何从mysql中检索pdf并使用php显示
- c - 为什么必须在同一个翻译单元中定义回调函数才能正确链接?
- html - 如何引用其他文件夹?
- powershell - Call Rest API inside powershell function
- angular - 数据表在角度 html 视图中无法正常工作
- c - 我是否成功释放了动态分配的内存?
- r - 如何使用 stan_glm 从以前的研究中定义信息先验?