这是一个调用 chararrays 和 integers 堆栈中的数组的函数。它应该反转值,但首先我必须弄清楚哪个是字符串,哪个是整数,然后才能切换它们。但我不断收到错误。这有什么可笑的吗?
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);
}
}
}