stc32g屠龙刀开发板,使用strcmp函数问题。
本帖最后由 大雨 于 2024-4-4 15:06 编辑stc32g屠龙刀开发板,使用strcmp函数问题。
STC32G芯片 代码用strcmp库文件,不能通过编译。已经加头文件了#include <string.h>
一直找到原因
代码在CodeBlocks上正常运行,加入模块后在Keil上编译就不能通过,好像Keil_c251原始安装文件里就没有string.h,是自己后加上的不,忘了。。。。
int find_product(char *name) {int i;
for (i = 0; i < sizeof(products) / sizeof(products); i++) {
if (strcmp(products.name, name) == 0)
{
return i;
}
}
return -1;
}
是不是只添加了头文件,没有函数体啊 lezjin 发表于 2024-4-4 17:27
是不是只添加了头文件,没有函数体啊
下了一个STRCMP原始函数,用笨方法解决了。另外可能是KEIL_c251安装库文件string.h被替换过,记不清了
那可能是被误删了?建议卸载c251,再重新安装 Snapdragon 发表于 2024-4-11 12:34
那可能是被误删了?建议卸载c251,再重新安装
是的 int My_strcmp (const char * src, const char * dst)//字符串比对
{
int ret = 0 ;
while( ! (ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst)
++src, ++dst;
if ( ret < 0 )
ret = -1 ;
else if ( ret > 0 )
ret = 1 ;
return( ret );
}
页:
[1]