鱼C论坛

 找回密码
 立即注册
查看: 1639|回复: 6

[已解决]小甲鱼课上指针数组与数组指针

[复制链接]
发表于 2021-11-16 18:30:39 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 林江楠 于 2021-11-25 10:12 编辑
#include <stdio.h>

int main()
{
        char *p1[5] = {
                "让编程改变世界 -- 鱼C工作室",
                "Just do it -- NIKE",
                "一切皆有可能 -- 李宁",
                "永不止步 -- 安踏",
                "One more thing... -- 苹果"
        };
        int i;

        for (i = 0; i < 5; i++)
        {
                printf("%s\n", p1[i]);
        }

        return 0;
}

[fishc@localhost s1e23]$ gcc test3.c && ./a.out



我的编译器警告了,就在定义指针数组那里,咋回事



D:\桌面\未命名8.cpp        In function 'int main()':
11        9        D:\桌面\未命名8.cpp        [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
11        9        D:\桌面\未命名8.cpp        [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
11        9        D:\桌面\未命名8.cpp        [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
11        9        D:\桌面\未命名8.cpp        [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
11        9        D:\桌面\未命名8.cpp        [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
最佳答案
2021-11-25 10:38:32
林江楠 发表于 2021-11-25 10:12
D:\桌面\未命名8.cpp        In function 'int main()':
11        9        D:\桌面\未命名8.cpp        [Warning] deprecated conve ...

.cpp 是C++源文件,把后缀改成 .c
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-11-16 18:47:02 | 显示全部楼层
什么警告?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-11-16 18:49:56 | 显示全部楼层
/home/aaa/Desktop/WorkSpace/Codes/test
让编程改变世界 -- 鱼C工作室
Just do it -- NIKE
一切皆有可能 -- 李宁
永不止步 -- 安踏
One more thing... -- 苹果
Process finished with exit code 0

我复制粘贴的你的代码,编译运行没有任何毛病啊。
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-11-17 00:11:30 | 显示全部楼层
运行了,没毛病,没有任何警告
dddddd.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-11-25 10:03:07 | 显示全部楼层
没有问题。
去去去.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-11-25 10:12:41 | 显示全部楼层

D:\桌面\未命名8.cpp        In function 'int main()':
11        9        D:\桌面\未命名8.cpp        [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
11        9        D:\桌面\未命名8.cpp        [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
11        9        D:\桌面\未命名8.cpp        [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
11        9        D:\桌面\未命名8.cpp        [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
11        9        D:\桌面\未命名8.cpp        [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-11-25 10:38:32 | 显示全部楼层    本楼为最佳答案   
林江楠 发表于 2021-11-25 10:12
D:\桌面\未命名8.cpp        In function 'int main()':
11        9        D:\桌面\未命名8.cpp        [Warning] deprecated conve ...

.cpp 是C++源文件,把后缀改成 .c
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-23 03:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表