gpt4 book ai didi

c - 如何用字符串替换宏?

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

#include <stdio.h>
#include <stdarg.h>
#define ammo "full"

int main()
{
char a[100];
a = ammo;
printf("%s",a);
return 0;
}

我正在尝试替换#define ammo"full" (字符串)并希望将其打印在屏幕上以检查其是否有效,但代码未编译。

最佳答案

代替a=弹药;你应该使用 strcpy(a,ammo);当有字符串时,不应使用直接赋值,而应使用 C 方法 strcpy 将字符串复制到另一个字符串。它会起作用的

关于c - 如何用字符串替换宏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45918982/

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