c语言 - 如何更正这些"Expected Expression Before 'Stack'"和"Not Enough Arguments to Function 'Push'"错误?



这是我在此站点上提出的第一个问题。我正在处理的程序应该检查一个字符串,以确保字符串中发现的所有定界器匹配('('and'),'['and'],等等)。虽然我确定一旦这些错误得到纠正,它就不会立即起作用,但我至少希望能够运行有缺陷的程序并从那里进行。

我认为代码的相关段位于我的有限状态机子程序的下一节中,以及我的Push and Pop子程序:

#include <stdio.h>
#include <stdlib.h>
#include "boolean.h"

typedef struct stacknode {
      char data;
      struct stacknode *next;
} *stack;

char fms(stack *, char); /*Prototypes for relevant subprograms*/

char fms(stack *s, char input){
   int state = 0;
   char i = -1, o, c;
   while(1) {
      switch(state) {
         case '0': i = i++;
                   if (isopen(input))
                      state = 1;
                   else {
                      if (isclose(input))
                         state = 2;
                      else {
                         if (input == '')
                            state = 3;
                         else
                            state = 4;
                      }
                   }
            break;
         case '1': push(stack *s, o); /*Two errors here. "Expected expression before 'Stack', and "Not enough arguments to function 'Push'".*/
                   state = 0;
            break;
         case '2': if(!is_empty) {
                      c = input;
                      o = pop(&stack *s); /*One error here. "Expected expression before 'Stack'".*/
                      if(!isbrother(o, c)) {
                         printf("Error: Pair does not match.");
                         return FALSE;
                      }
                   }
                   else {
                      printf("Error: Too many closing delimiters.");
                      return FALSE;
                   }
                   state = 0;

请记住,我决定仅显示与错误相关的FMS子程序的一部分。否则很长。

void push(stack *s, char o) {
   stack temp;

   temp = (stack) malloc(sizeof(struct stacknode));
   temp->data = o;
   temp->next = (*s);
   (*s) = temp;
}

char pop(stack *s) {
   stack temp;
   char data_popped;

   temp = *s;
   data_popped = temp->data;
   *s = temp->next;
   free (temp);
   return data_popped;
}

大家的任何帮助都会不胜感激。一旦处理这些错误,我应该能够找出其余的。

case '1': push(stack *s, o);您应该在没有数据类型的情况下调用传递参数(例如通过值或参考)来调用函数。

您只需要通过变量为

push(s, o); //Where s holds the base address

不做:

push(stack *s, o)

push(s, o)

由于您不需要在调用函数时声明变量的类型,因此只有在声明函数本身时。

相关内容

最新更新