你好,我只需要看看为什么我的 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/