gpt4 book ai didi

连接多个字符串?

转载 作者:太空宇宙 更新时间:2023-11-04 06:08:26 25 4
gpt4 key购买 nike

我有一行如下所示,但我需要为目录连接斜线,有什么方法可以安全地连接多个字符串吗?

// Need to include \\ after windowsDir
FILE *dest = fopen(strcat(windowsDir, filename),"wb");

最佳答案

char *buf = malloc(strlen(windowsDir) + 1 + strlen(filename) + 1); // len + \ + len + \0
sprintf(buf, "%s\\%s", windowsDir, filename);
FILE *dest = fopen(buf, "wb");
free(buf);

关于连接多个字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5266989/

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