C 使用堆栈错误反转字符串:参数1的类型不兼容';顶部'|
在这种情况下,你会遇到一个问题,因为C 使用堆栈错误反转字符串:参数1的类型不兼容';顶部'|,c,C,在这种情况下,你会遇到一个问题,因为 您在for循环中重新声明了类型为int的变量a,它超越了a的先前定义,并给出了无效参数的错误 您将错误的参数类型传递给strcattop(a)->valuehas type char,但是strcat接受char* 即使您将其更改为类型char*(通过执行&(top(a)->value)),您也会遇到问题,因为top(a)->value是一个不以null结尾的单个字符,strcat将不知道何时停止从源代码复制 您可能应该做的是通过数组访问st,例如st[i]
int
的变量a,它超越了a
的先前定义,并给出了无效参数的错误top(a)->value
has type char,但是strcat
接受char*
char*
(通过执行&(top(a)->value)
),您也会遇到问题,因为top(a)->value
是一个不以null结尾的单个字符,strcat
将不知道何时停止从源代码复制您可能应该做的是通过数组访问
st
,例如st[i]=top(a)->value
,然后退出for循环后将其终止为null。在这种特殊情况下,您将遇到一个问题,因为
int
的变量a,它超越了a
的先前定义,并给出了无效参数的错误top(a)->value
has type char,但是strcat
接受char*
char*
(通过执行&(top(a)->value)
),您也会遇到问题,因为top(a)->value
是一个不以null结尾的单个字符,strcat
将不知道何时停止从源代码复制您可能应该做的是通过数组访问
st
,例如st[i]=top(a)->value
,然后退出for循环后将其null终止。首先在for
循环中,您将a
重新声明为int
,这将是隐藏变量a
在main中声明为stack
。因此,将a
更改为其他内容:
incompatible type for argument 1 of 'top'|" at this instruction " strcat(st,top(a)->value);
由于top(a)->value
将是节点中存储的字符,您可以直接将其分配给字符串:
strcat(st,top(a)->value);
^
char * is expected but argument is of type char.
intj;
对于(j=0;j值;
流行音乐(a);
}
st[j]='\0';/*别忘了以null结尾字符串*/
首先,在for
循环中,您将a
重新定义为int
,这将是隐藏变量a
在main中声明为stack
。因此,将a
更改为其他内容:
incompatible type for argument 1 of 'top'|" at this instruction " strcat(st,top(a)->value);
由于top(a)->value
将是节点中存储的字符,您可以直接将其分配给字符串:
strcat(st,top(a)->value);
^
char * is expected but argument is of type char.
intj;
对于(j=0;j值;
流行音乐(a);
}
st[j]='\0';/*别忘了以null结尾字符串*/
为什么需要top()
函数?为什么不直接使用a.top
?@e0ktop()
是朝着这个方向迈出的有用一步。为什么您需要top()
函数呢?为什么不直接使用a.top
?@e0ktop()
是迈向成功的有用一步。
int j;
for(j = 0; j < i; j++){
st[j] = top(a)->value;
pop(&a);
}
st[j] = '\0'; /* Don't forget to null-terminate your string. */