gpt4 book ai didi

c - 如何获取char*的子串

转载 作者:行者123 更新时间:2023-11-30 20:55:58 25 4
gpt4 key购买 nike

我有以下内容

char* str = "Some string";

如何从 n 获取子字符串至m str的符号?

最佳答案

如下代码:

int m = 2, n = 6;
char *p = (char *)malloc(sizeof(char) * (n - m));
for (size_t i = m; i < n; i++)
{
p[i - m] = str[i];
}
if(p)
printf("Memory Allocated at: %x/n",p);
else
printf("Not Enough Memory!/n");
free(p);

关于c - 如何获取char*的子串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29250618/

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