冲突类型错误

标签 c types

当我运行以下代码时,出现错误

 problem1.c:136:6: error: conflicting types for 'strcspn' 
   int strcspn( char * str, char * reject ) 

我不确定为什么会收到冲突类型错误。 这是代码:

int strcspn( char * str, char * reject ) 
{

    int counter = 0;

    for (int i = 0; i < strlen(str); i ++)
    {       for (int j = 0; j < strlen(reject); j++)
                if ( *(str + i) == *(reject + j) )
                return counter;
        counter++;
    }

return counter;

}


void main ()
{


char * str1 = (char *)malloc(sizeof(char)*100);
char * str2 = (char *)malloc(sizeof(char)*100);
sprintf(str1, "abc123");
sprintf(str2, "d2");
printf("%d\n", strcspn(str1, str2)); 

}

最佳答案

strcspn声明于 <strings.h> 。看起来您以某种方式包含了该 header ,然后尝试重新定义 strcspn与头文件定义不同。在我的<strings.h>它被定义为

 size_t strcspn(const char *s, const char *reject);

关于冲突类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33572503/

相关文章:

c - useDynLib() 错误且compileAttributes 不返回任何内容 : embedding a C library into an R package

javascript - 有没有办法使用数字类型作为对象键?

c# - 在 C# 中将有符号整数与无符号整数相加

c - 在像 C 这样的编程语言的上下文中,数组数据结构和数组数据类型有什么区别?

java - Scala/Java 中的编程语言抽象

c - 使用 inotify 跟踪特定 PID 的 in_open 和 in_close 事件

c - 以下两个调用中哪一个肯定是有效的,为什么?

c - 如何在 C 中将一个字符中的两个数字相加?

c - 用 C 语言控制任务内存的程序

haskell - 了解具有类约束的 2 级类型别名