我很困惑。我正在一个需要使用strcmp的项目中,它似乎根本没有工作。在上面的示例中,您看到了gdb中的两个字符不相等的示例。当我比较两个char数组时,结果显然相似。此外,当我将数组与其自身进行比较时,我也会得到false(上面的名称是char [8])。当我在同一阵列上的代码中运行strcmp时,它会产生正确的结果,但不会在gdb中显示(在第三张图中看到),我只需要在哪里查找/做什么就可以。
谢谢。
编辑:图像中的两个代码片段:
print strcmp("S", "S")==0
print strcmp(name, name)==0
答案 0 :(得分:3)
您使用了错误的引号。
order by year
函数期望两个参数都为update t t1
set batch = t2.batch
from ( select id,
count(id) over
(partition by year
order by coalesce(batch,0) , id ) as batch
from t
) as t2
where t1.id = t2.id
类型,即指向以空终止的字符串的指针。在C ++(和C)中,单引号用于单字符,而双引号用于以null结尾的字符串。因此,您没有传递正确类型的参数。
进行此比较的正确方法是:
strcmp
答案 1 :(得分:2)
当字符串相等时,strcmp返回0,false,我认为您期望的是1,true。但是,就是这样。您可以将其包装在自己的函数中,然后函数可以返回true。