c - 尝试使用 strlen 但出现错误 : Conflicting types for 'strlen'

标签 c string file strlen

我不知道是什么原因导致这个问题...感谢任何帮助! 我已经尝试了很多 strlen 代码,但这是唯一一个我可以实现且只有 1 个错误的代码。使用此代码,我尝试从文件中读取字符串,将其分解为由空格分隔的单词,确定长度,然后将单词和长度打印给用户。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

FILE*arquivo;
char nuks[80];
char frase[80];

typedef struct node {
char palavra;
struct node* esquerda;
struct node* direita;
int altura;
} No;

size_t strlen(char *nstr)
{
int total=0;
char str[80];
strcpy(str, nstr);
total = strlen(str);
printf("|%s| is |%d|", str, total);
}

int main()
{
No* raiz = NULL;
arquivo=fopen("README.txt","r");
fgets(nuks, 79, arquivo);
printf("%s\n",nuks);

char *parte;

// Get the first word
parte = (char*)strtok(nuks, " ");

// Get the other words
while(parte != NULL){
strlen(parte);
printf("%s\n", parte);
parte = (char*)strtok(NULL, " ");
}

printf("\n\n");
system("pause");
return 0;
}

最佳答案

您正在将一个名为 strlen() 的函数调用到另一个也名为 strlen() 的函数中,这使其成为递归函数,更糟糕的是,无限递归! 除此之外,您不需要将 nstr 的本地副本放入 str 只是为了确定其长度。 最后,有什么理由不使用 string.h 中声明的标准 strlen() 函数吗?

关于c - 尝试使用 strlen 但出现错误 : Conflicting types for 'strlen' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30746010/

相关文章:

c - 在 C 中使用多个函数参数来返回多个值是不好的做法吗?

c - Vigenere 未能使用 C 中的 “BaRFoo” 错误进行 check50 测试将 “CaQGon” 加密为 “BaZ”

c - 在 C 中处理具有长度的字符串

java - 在 Java 中读取和写入 .txt 文件

debugging - 海湾合作委员会/gdb : How to embed absolute path to source file in debug information?

Python快速更改8KK行文件中的300K行

c - 在 C 中调试堆栈溢出?

C:有什么叫做 'prefix expression' 的东西吗?

android - 关于 Android 公钥的说明?

python - Python 中的显式行连接