Как исправить ошибки ожидаемых идентификаторов C Язык

Я получаю две ошибки "ожидаемого идентификатора" при компиляции своего кода, даже если он написан в соответствии со стандартами ANSI-C. Я скомпилировал с помощью компилятора gcc с флагами -Wall -ansi -pedantic. Я знаю, что компилятор старый, но мой университет требует от меня его использования.

Скопируйте и вставьте ошибки:

mycomp.c:202:5: error: expected identifier or ‘(’ before ‘return’
     return SUCCESS;
     ^
mycomp.c:203:1: error: expected identifier or ‘(’ before ‘}’ token
     }
     ^
makefile:10: recipe for target 'mycomp.o' failed

Я попытался просмотреть свой код и не могу найти никаких проблем с синтаксисом. Я попытался, следуя инструкциям по ошибкам, например, добавить токен '(' before 'return' или '(' before '}', но это ничего не меняет, и я все еще получаю эти ошибки.

Код длинный и грязный, но я получаю сообщение об ошибке только в самом конце или в нем: последнее возвращение и последнее} цифра.

int main() {  
    char command[SIZE_OF_LINE];
    int commandIndex; int i;
    int numbers[2]; char var[2];

    /* As requested, initializing all complex values to 0 + 0i */
    read_comp(A, NONE, 0 ,0);
    read_comp(B, NONE, 0 ,0);
    read_comp(C, NONE, 0 ,0);
    read_comp(D, NONE, 0 ,0);
    read_comp(E, NONE, 0 ,0);
    read_comp(F, NONE, 0 ,0);

    commandIndex = 0;

    numbers[0] = commandIndex;
    numbers[1] = commandIndex;
    var[0] = '0';
    var[1] = '0';

    for(i = 0; ; i = 0)
        if(!fgets(command, SIZE_OF_LINE, stdin)) {
            i = undefinedCharSkipper(command, i);
            commandIndex = commandIdentifier(command, i);

            if(cmd[commandIndex].func == NULL) {
                fprintf(stderr, "Command does not exist:%s\n", command);
            }

            if(strcmp(cmd[commandIndex].name, "read_comp") == 0) {
                /* Recieving parameters and setting in place */
                i = undefinedCharSkipper(command, i);
                if(letterReceiver(i) != FAIL) {
                    var[0] = letterReceiver(i);
                }

                i = undefinedCharSkipper(command, i);
                if(numberReceiver(command, i) != FAIL) {
                    numbers[0] = numberReceiver(command, i);
                }

                i = undefinedCharSkipper(command, i);
                if(numberReceiver(command, i) != FAIL) {
                    numbers[1] = numberReceiver(command, i);
                }

                /* Running command */
                read_comp(getComplex(var[0]), NONE, numbers[0], numbers[1]);
                end(command, i);
            }

            if(strcmp(cmd[commandIndex].name, "print_comp") == 0 ) {
                /* Recieving parameters and setting in place */
                i = undefinedCharSkipper(command, i);
                if(letterReceiver(i) != FAIL) {
                    var[0] = letterReceiver(i);
                }

                /* Running command */
                print_comp(getComplex(var[0]), NONE, 0, 0);
                end(command, i);
            }

            if(strcmp(cmd[commandIndex].name, "add_comp") == 0 ) {
                /* Recieving parameters and setting in place */
                i = undefinedCharSkipper(command, i);
                if(letterReceiver(i) != FAIL) {
                    var[0] = letterReceiver(i);
                }

                i = undefinedCharSkipper(command, i);
                if(letterReceiver(i) != FAIL) {
                    var[1] = letterReceiver(i);
                }

                /* Running command */
                add_comp(getComplex(var[0]), getComplex(var[1]), 0, 0);
                end(command, i);
            }

            if(strcmp(cmd[commandIndex].name, "sub_comp") == 0) {
                /* Recieving parameters and setting in place */
                i = undefinedCharSkipper(command, i);
                if(letterReceiver(i) != FAIL) {
                    var[0] = letterReceiver(i);
                }

                i = undefinedCharSkipper(command, i);
                if(letterReceiver(i) != FAIL) {
                    var[1] = letterReceiver(i);
                }

                /* Running command */
                sub_comp(getComplex(var[0]), getComplex(var[1]), 0, 0);
                end(command, i);
            }

            if(strcmp(cmd[commandIndex].name, "mult_comp_real") == 0) {
                /* Recieving parameters and setting in place */
                i = undefinedCharSkipper(command, i);
                if(letterReceiver(i) != FAIL) {
                    var[0] = letterReceiver(i);
                }

                i = undefinedCharSkipper(command, i);
                if(numberReceiver(command, i) != FAIL) {
                    numbers[0] = numberReceiver(command, i);
                }

                /* Running command */
                mult_comp_real(getComplex(var[0]), NONE, numbers[0], 0);
                end(command, i);
            }

            if(strcmp(cmd[commandIndex].name, "mult_comp_img") == 0) {
                /* Recieving parameters and setting in place */
                i = undefinedCharSkipper(command, i);
                if(letterReceiver(i) != FAIL) {
                    var[0] = letterReceiver(i);
                }

                i = undefinedCharSkipper(command, i);
                if(numberReceiver(command, i) != FAIL) {
                    numbers[0] = numberReceiver(command, i);
                }

                /* Running command */
                mult_comp_img(getComplex(var[0]), NONE, 0, numbers[0]);
                end(command, i);
            }

            if(strcmp(cmd[commandIndex].name, "mult_comp_comp") == 0) {
                /* Recieving parameters and setting in place */
                i = undefinedCharSkipper(command, i);
                if(letterReceiver(i) != FAIL) {
                    var[0] = letterReceiver(i);
                }

                i = undefinedCharSkipper(command, i);
                if(letterReceiver(i) != FAIL) {
                    var[1] = letterReceiver(i);
                }

                /* Running command */
                mult_comp_comp(getComplex(var[0]), getComplex(var[1]), 0, 0);
                end(command, i);
            }

            if(strcmp(cmd[commandIndex].name, "abs_comp") == 0) {
                /* Recieving parameters and setting in place */
                i = undefinedCharSkipper(command, i);
                if(letterReceiver(i) != FAIL) {
                    var[0] = letterReceiver(i);
                }

                /* Running command */
                abs_comp(getComplex(var[0]), NONE, 0, 0);
                end(command, i);
            }

            if(strcmp(cmd[commandIndex].name, "stop") == 0) {
                stop(NONE, NONE, 0, 0);
                end(command, i);
            }
        }
        else { /* Failed scanning the user's input */
            printf("\n");
            printf("Scanning had failed");
            printf("\n");
        }
    }
    return SUCCESS;
}

Ожидаемые результаты: компиляция без ошибок, так как это только две ошибки, которые я получаю. Фактические результаты: получение 2 ошибок.

1 ответ

Решение

Внимательно посмотрите и сделайте отступ в своем коде.

В части

    }                     //----------------------- (1)
    return SUCCESS;        // -----------------------(2)
}                     

У вас несоответствие фигурных скобок., (1) указывает закрывающую скобку для main() функция, поэтому часть помечена как (2); ваш return SUCCESS; } находится в области видимости файла, что запрещено.

Исправьте отступы и позаботьтесь о брекетах.

Другие вопросы по тегам