C,gcc错误编译简单程序

时间:2014-10-07 20:58:13

标签: c gcc

当我尝试编译非常简单的C游戏时,我遇到了一些问题。

它说:

“第125行错误:预期标识符或'('返回'之前'   返回0;“

“第126行错误:预期标识符或'('''''''令牌  }“

(第125和126行是我代码中的最后两行)

<#include <stdio.h>
    #include <time.h>
    #include <stdlib.h>



    int main (void)

    {

        int headbang,x,y,fx,fy;
        char choice;

        headbang = 0;



    {
     srand(1); 
     int fx = rand()%5 + 1; 
    }
     {
     srand(2); 
     int fy = rand()%5 + 1; 
    }
     {
     srand(3); 
     int x= rand()%5 + 1; 
     }
     {
     srand(4); 
     int y= rand()%5 + 1; 
     }


        printf ("It is pitch black. You have no idea how you got here, but you \nknow that you have to find some source of light in order to get \nout. \n \n");



        printf ("Where do you want to go? ");


        {
        scanf(" %c", &choice);


        switch (choice) 
    {
        case 'n':
    x++;

    printf ("You crawl North.\n");
    break;



        case 's':
    x--;

    printf("You crawl South \n");


        case 'e':

    y++;

    printf ("You crawl East.\n");
    break;

        case 'w':


    y--;

    printf ("You crawl West.\n");
    break;

    default:
    printf ("Sorry, you can only go north, south, east or west.");


    }
        if (x==0 || y==0 || x==6 || y==6)
    {
    printf("Ouch! You hit your head in the wall.");
    headbang++;

        if (x==0)
    {
    x++;
    }

        else if (y==0)
    {
    y++;
    }

        else if (x==6)
    {
    x--;
    }

        else if (y==6)
    {
    y--;
    }

    }

        if (headbang == 2)
    {
    printf ("You slip into a deep sleep, never to wake up again...");
    }

        if (x==fx && y==fy)
    {
    printf("You feel something on the floor. It is a flashlight! \n You wake up, finding yourself in your own bed. What a nightmare!");
    break;
    }


    while (!(x==fx && y==fy));  
    }
    }   
        return 0;
    }

1 个答案:

答案 0 :(得分:3)

你应该把回报放在倒数第二个}之前,并删除最后一个括号