这是一个函数,它调用一堆栈和整数中的数组。它应该颠倒这些值,但首先我必须弄清楚哪些是字符串,哪些是整数,然后才能切换它们。但我不断收到错误。有什么看起来可笑吗?反向函数不断给我错误
void reverse(Stack *S)
// NOTE: Called w/ user input 'r'
// PRE: Stack S is initialized
// POST: The first two values of the stack are reversed on the stack
{
int valone;
int valtwo;
char stringone[50];
char stringtwo[50];
if (S->size < 1)
{
printf("Error: There are less than 2 values on the stack \n");
}
else
{
valone = (float)topInt(S);
strcpy(stringone, topString(S));
pop(S);
valtwo = (float)topInt(S);
strcpy(stringone, topString(S));
pop(S);
if(stringone[0] == '\n')
{
pushInt(S, valone);
}
else if(valone == '\n')
{
pushString(S, stringone);
}
else if(stringtwo[0] == '\n')
{
pushInt(S, valtwo);
}
else if(valtwo == '\n')
{
pushString(S, stringtwo);
}
}
}
你得到了什么样的错误? – asbumste
其中是Stack类型的定义?为什么你使用一个强制转换来将该值存储在一个int中?为什么有时候你会推弦,有时整数?您的代码令人困惑... – vmp