任何人都可以帮我调试这段代码,因为它在中间停止工作

标签 c gcc

你好,我只需要看看为什么我的 Gcc 在执行后停止工作。

#include<stdio.h>
int main()
{
static char *s[] = {"black", "white", "pink", "violet"};
char **ptr[] = {s+3, s+2, s+1, s}, ***p;
p=ptr;
++p;
printf("the value of **p is %s\n\t",**p); // printed on screen pink
printf("the value of **ptr[1] is %s\n\t",**ptr[1]); // here got the error
printf("the value of *(s[2]) is %s\n\t",*s[2]); // here got the error
return 0;
}

最佳答案

**ptr[1] 是一个 char。您将其传递给 printf 进行 %s 转换。 %s 需要一个指向 char 的指针,而不是 char。改为传递 *ptr[1]

同样,传递 s[2],而不是 *s[2]

关于任何人都可以帮我调试这段代码,因为它在中间停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49547136/

相关文章:

c - 从内核模块获取对输入设备的引用

c - Makefile 无法为简单项目创建单独的对象文件夹

C++ 将文件读入字符数组

linux - 在 64 位模式下编译 NASM 代码时出现重定位错误

c++ - 符号可见性和 gcc 警告

c - 如何在 OSX Sierra 上安装 gcc 4.2.1?

c - ptr = &a 和 *ptr = a 意思一样吗?

c - C 中动态的、大小不可预测的数组

比较字符串中的char与C中的指针

c - 对齐堆栈是什么意思?