c - 确定从某个单元格开始的数组是否包含字符串的函数?
问题描述
*** C 新手在这里。***
我的程序有一个包含 HTML 文档的数组(每个 HTML 字符一个数组单元格)。我有一个循环遍历数组的每个单元格。在每个数组单元格中,我检查单元格值是否是某个字符串的开头;例如,当前单元格是否包含“&”,下一个单元格是否包含“n”和下一个“b”,然后是“s”,然后是“p”,然后是“;” (即," "
)。
我写了一个函数来做比较。见下文。C 是否已经有一个可以进行这种比较的函数?如果不是,我在下面展示的函数是 C 专家如何编写的吗?如果不是,C 专家将如何编写该函数?
// p points to a cell in an array
// s is a string
// This function answers the question: does p start with s?
int cmpString(char *p, char *s) {
char *q = p; // Don't modify the position of the array pointer so make a copy
while (*s != 0) {
if (tolower(*q) != tolower(*s))
return 0;
q++;
s++;
}
return 1;
}
解决方案
推荐阅读
- python - Docker Flask - jinja2.exceptions.TemplateNotFound 错误
- python-3.x - Python3 - YAML 未正确在列表中附加值
- javascript - Why is the for loop ending very early?
- rxjs - 延迟无限流的每个值
- docker - 在 Alpine Docker 上安装 Scipy 时准备轮元数据时出错
- sql-server - SQL Server 中的表没有自然键
- ironpython - Spotfire IronPython - 更改可视化列
- sql - 用不同的条件子查询同一列
- c++ - 同时旋转多个立方体的问题
- java - 如何获取 AWS WAF 详细信息列表