【发布时间】:2026-02-05 15:10:01
【问题描述】:
我是 C 的新手。我有这种类型的代码,当我尝试执行它时,显示此警告消息“传递 'snprintf' 的参数 1 从指针目标类型中丢弃 'const' 限定符”和什么也没发生。
我做错了什么? 谢谢
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int i;
const char *msg[3] = {"Hello", "Good Morning", "Hello World"};
const char *strings[];
for(i=0; i<3; i++)
snprintf(strings[i], 20, "%s %d", msg[i], i);
for(i=0; i<3; i++)
printf("strings[%d]: %s\n", i, strings[i]);
return 0;
}
【问题讨论】:
标签: c arrays char printf constants