gpt4 book ai didi

将 const char 转换为数组

转载 作者:太空宇宙 更新时间:2023-11-03 23:30:49 24 4
gpt4 key购买 nike

我正在尝试将 const char 转换为 char...这是我的代码:

bool check(const char* word)
{

char *temp[1][50];

temp = word;

return true;
}

它是一个传入 const char 的函数。我需要将该 const char 转换为 char。当我现在运行这段代码时,编译器抛出了这个错误:

dictionary.c:28:6: error: array type 'char *[1][50]' is not assignable
temp = word;

如何正确完成此转换?

谢谢,乔希

最佳答案

#include <string.h>
bool check(const char* word)
{
char temp[51];
if(strlen(word)>50)
return false;
strncpy(temp,word,51);
// Do seomething with temp here
return true;
}

关于将 const char 转换为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15989892/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com