Arrays 为什么strlen()没有返回正确的值?

Arrays 为什么strlen()没有返回正确的值?,arrays,c,string,libraries,Arrays,C,String,Libraries,嗨,我很抱歉,这是一种重复,但没有其他解决方案能够帮助我。find和tofind变量都是“Point”,但是当我调用strcmp时,我得到一个负数,当我打印它们的长度时,find的len为9。有人能帮我理解为什么会这样以及如何修复(如何使found和tofind具有相同的值和长度)?非常感谢你 #include <stdio.h> #include <string.h> #include <stdbool.h> int main(void) { char

嗨,我很抱歉,这是一种重复,但没有其他解决方案能够帮助我。find和tofind变量都是
“Point”
,但是当我调用
strcmp时,我得到一个负数,当我打印它们的长度时,find的len为9。有人能帮我理解为什么会这样以及如何修复(如何使found和tofind具有相同的值和长度)?非常感谢你

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

int main(void) {
  char found[] = "";
  char tofind[] = "Point";


  int i = 0;

  while(i < 5){
    char f = tofind[i];


    strcat(found, &f);
    i++;

  }

  int r = strcmp(found, tofind);
  printf("%d\n", r);

  printf("Found: %s with len: %lu\n", found, strlen(found));//says len is 9

  printf("To Find: %s with len: %lu", tofind, strlen(tofind)); //says len is 5

return 0;
}

@支付此呼叫strcat(已找到,&f);没有道理。找到的数组只有一个元素。
strcat(已找到,&f)此行
strcat(已找到,&f)调用未定义的行为,因为它将导致读取(传递非空终止的内容)和写入(连接到1元素数组)的访问超出范围。@Blindy为什么决定它是只读节?!欺骗:
./main
-104
Found: Point with len: 9 this is i: 5
To Find: Point with len: 5