在C中修改rindex

时间:2012-12-16 06:54:13

标签: c string

我在C(Linux OS)中编程。我需要使用rindex来查找指定为函数参数的char的最后一次出现。

char * rindex (const char *string, char c);

虽然我收到了警告但它仍能正常工作:

conflicting types for built-in function ‘rindex’ [enabled by default]

但是如果我包含string.h标题。它给出了错误,

conflicting types for ‘rindex’

因为rindex被定义为,

char * rindex (const char *string, int c);

但我需要将它用作char,并使用string.h进行字符串操作。有可能吗?请指导我。

2 个答案:

答案 0 :(得分:2)

在第7版UNIX™中,有两个函数index()rindex()分别等同于标准C函数strchr()strrchr(),给出或取const 1}}(在定义这些函数时不存在,不仅仅存在原型;当时甚至没有带Classes的C语言。)

你正在违反函数rindex()的向后兼容声明。名称index()rindex()是陈旧的,但您不能在自己的代码中巧妙地使用它们。选择其他功能名称。

答案 1 :(得分:0)

/* include standard string */
#include <string.h>
/* alias standard rindex to rindex_std */
#define rindex rindex_std
/* include your OS defined strings.h */
#include <strings.h>

这将解决冲突。

相关问题