使用 strcmp 进行比较
使用 gcc C99 进行编译
我正在尝试使用字符串比较来比较 2 个字符串。 但是,我似乎在 strcmp 行上得到了堆栈转储。
**属性将包含这些,所以我正在寻找框架类型。
[name] [time] [type] [time]
[name] [callref] [type] [string]
[name] [port] [type] [int16]
[name] [frametype] [type] [int16]
这是正确的比较方法吗?
非常感谢您的任何建议,
void g_start_element(void *data, const char *element, const char **attribute)
{
for(i = 0; attribute[i]; i++)
{
/* Only interested in the frametype */
if(strcmp(attribute[i], "frametype") == 0)
{
/* do some work here */
}
}
}
compiling with gcc C99
I am trying to compare 2 string using string compare.
However, I seem to be getting a stack dump on the strcmp line.
**attribute will contain these, so I am looking for frametype.
[name] [time] [type] [time]
[name] [callref] [type] [string]
[name] [port] [type] [int16]
[name] [frametype] [type] [int16]
Is this correct way to compare.
Many thanks for any suggestions,
void g_start_element(void *data, const char *element, const char **attribute)
{
for(i = 0; attribute[i]; i++)
{
/* Only interested in the frametype */
if(strcmp(attribute[i], "frametype") == 0)
{
/* do some work here */
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(7)
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您需要有一个空字符串才能终止 for 循环:
如果没有这个,for 循环将不会终止,并且当您调用 strcmp 时,您将得到指向垃圾的 attribute[i]。
You'll need to have a null string in order to terminate the for loop:
Without this the for loop won't terminate and you'll end up with attribute[i] pointing to garbage when you call strcmp.