(c) I';我在这方面遇到了麻烦,每次我试图执行程序时,它都会崩溃

(c) I';我在这方面遇到了麻烦,每次我试图执行程序时,它都会崩溃,c,windows,C,Windows,我使用的编译器是pelles C如果这对我有帮助的话,这对我回答这个问题非常重要!这是一个对房子的口头演练,程序没有发现任何错误,但我无法让它工作 #include <stdio.h> #include <conio.h> #include <string.h> #include <stdlib.h> #define North 0 #define East 1 #define South 2 #define West 3 void Setup

我使用的编译器是pelles C如果这对我有帮助的话,这对我回答这个问题非常重要!这是一个对房子的口头演练,程序没有发现任何错误,但我无法让它工作

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>

#define North 0
#define East 1
#define South 2
#define West 3

void SetupRooms();
void DescribeRoom(unsigned int RN);
void DescribeExits(unsigned int RN);
signed int GetDirection(unsigned int RN);

typedef struct{
    char Description[500];
    unsigned int Exit[4];

}Location;

Location Room [8];

int main(void){
    unsigned int Room = 1;
    signed int Direction;
    SetupRooms();

    while(1){
        _clrscr();
        DescribeRoom(Room);
        DescribeExits(Room);
        Direction = GetDirection(Room);
        if(Direction == -1){
            printf("\n BYE!\n");
            exit(0);
        }
        if (Direction>0)Room=Direction;
            else printf("\nSorry you can't go that way...\n");
    }
}

void SetupRooms(){
    strcpy(Room[1].Description, "Welcome to the Simonsen house, come on in!\n");
    Room[1].Exit[North]=7;
    Room[1].Exit[East]=0;
    Room[1].Exit[South]=0;
    Room[1].Exit[West]=2;
    strcpy(Room[2].Description, "You've entered the Hall! Signs of an busy family surround you; a pile of skateboards and an overflowing coat stand. You take off your shoes before continuing.\n");
    Room[2].Exit[North]=3;
    Room[2].Exit[East]=1;
    Room[2].Exit[South]=0;
    Room[2].Exit[West]=5;
    strcpy(Room[3].Description, "Fancy a drink while you're in the kitchen? If you hear a scrabbling noise don’t worry, it’s just Homer the Bearded Dragon.\n");
    Room[3].Exit[North]=0;
    Room[3].Exit[East]=7;
    Room[3].Exit[South]=2;
    Room[3].Exit[West]=4;
    strcpy(Room[4].Description, "So this is the dining room, feel free to play any of the musical instruments\n... or just look at the embarassing childhood photos...\n");
    Room[4].Exit[North]=7;
    Room[4].Exit[East]=3;
    Room[4].Exit[South]=5;
    Room[4].Exit[West]=6;
    strcpy(Room[5].Description, "Welcome to the living room, the centre of the house with its cheerful yellow and blue walls, cream leather corner sofa and hundreds of DVDs. See anything of interest?\n");
    Room[5].Exit[North]=4;
    Room[5].Exit[East]=1;
    Room[5].Exit[South]=0;
    Room[5].Exit[West]=0;
    strcpy(Room[6].Description, "Make sure you don't disturb the person revising! The study is filled with French teaching materials, random cables and liquor...\n");
    Room[6].Exit[North]=0;
    Room[6].Exit[East]=4;
    Room[6].Exit[South]=8;
    Room[6].Exit[West]=0;
    strcpy(Room[7].Description, "You pop on the clogs by the door and explore the garden.\nHow about you have a bounce on the trampoline while you're here?\n");
    Room[7].Exit[North]=0;
    Room[7].Exit[East]=3;
    Room[7].Exit[South]=4;
    Room[7].Exit[West]=0;
    strcpy(Room[8].Description, "The garage light turns on as you walk in and you try not to trip over anything.\n");
    Room[8].Exit[North]=6;
    Room[8].Exit[East]=0;
    Room[8].Exit[South]=1;
    Room[8].Exit[West]=0;
}

signed int GetDirection(unsigned int RN){
int NextRoom = 0;
unsigned char d;
printf("Type the first letter of the direction you wish to travel.");
printf("\nOr type q to quit\n");
d = _getch();
if (d == 'n') NextRoom = Room[RN].Exit[North];
if (d == 'e') NextRoom = Room[RN].Exit[East];
if (d == 's') NextRoom = Room[RN].Exit[South];
if (d == 'w') NextRoom = Room[RN].Exit[West];
if (d == 'q') NextRoom = -1;

return(NextRoom);
}

void DescribeExits(unsigned int RN){
    printf("\nExits are available to the: ");
    if(Room[RN].Exit[North]>0) printf("\n North");
    if(Room[RN].Exit[East]>0) printf("\n East");
    if(Room[RN].Exit[South]>0) printf("\n South");
    if(Room[RN].Exit[West]>0) printf("\n West");
}

void DescribeRoom(unsigned int RN){     
     printf("\n %s", Room[RN].Description); 
}
#包括
#包括
#包括
#包括
#定义北0
#定义东1
#定义南方2
#定义西部3
空房间();
无效描述符空间(无符号整数RN);
无效描述(无符号整数RN);
有符号整数方向(无符号整数RN);
类型定义结构{
字符描述[500];
无符号整数出口[4];
}位置;
位置室[8];
内部主(空){
无符号整数房间=1;
符号整数方向;
设置房间();
而(1){
_clrsc();
描述室(房间);
描述(房间);
方向=方向(房间);
如果(方向==-1){
printf(“\n拜拜!\n”);
出口(0);
}
如果(方向>0)房间=方向;
else printf(“\n您不能走那条路…\n”);
}
}
空房间(){
strcpy(房间[1]。描述,“欢迎来到西蒙森之家,请进!\n”);
[1]号房间,[北]出口=7;
房间[1]。出口[East]=0;
房间[1]。出口[South]=0;
[1]号房间,出口【西】=2;
strcpy(房间[2]。描述:“您已经进入大厅!一个忙碌的家庭的标志围绕着您;一堆滑板和一个满满的衣架。您在继续之前脱下鞋子。\n”);
[2]号房间,出口【北】=3;
房间[2]。出口[East]=1;
房间[2]。出口[South]=0;
[2]号房间。出口【西】=5;
strcpy(房间[3]。描述,“想在厨房喝点什么吗?如果你听到乱涂乱画的声音,别担心,那只是荷马的胡子龙。\n”);
房间[3]。出口[North]=0;
[3]号房间,出口【东】=7;
[3]号房间,[南]出口=2;
[3]号房间。出口【西】=4;
strcpy(房间[4]。描述,“这就是餐厅,您可以随意演奏任何乐器\n…或者只是看看令人尴尬的童年照片…\n”);
[4]号房间,出口【北】=7;
[4]号房间,出口【东】=3;
[4]号房间,[南]出口=5;
[4]号房间,出口【西】=6;
strcpy(房间[5]。描述:“欢迎来到客厅,这是房子的中心,有着令人愉快的黄蓝相间的墙壁,奶油色真皮沙发角和数百张DVD。看到感兴趣的东西了吗?\n”);
[5]号房间,出口【北】=4;
[5]号房间,出口【东】=1;
房间[5]。出口[South]=0;
[5]号房间,[West]出口=0;
strcpy(房间[6]。描述:“确保不要打扰正在修改的人!书房里堆满了法语教材、随机电报和酒……\n”);
房间[6]。出口[North]=0;
[6]号房间,出口【东】=4;
[6]号房间,[南]出口=8;
房间[6]。出口[West]=0;
strcpy(房间[7]。描述,“你在门边踩木屐,探索花园。\n在这里蹦床上蹦跳怎么样?\n”);
房间[7]。出口[North]=0;
[7]号房间,出口【东】=3;
[7]号房间,[南]出口=4;
房间[7]。出口[West]=0;
strcpy(房间[8]。描述:“当你走进车库时,车库灯会亮着,你会尽量不被任何东西绊倒。\n”);
[8]号房间,出口【北】=6;
房间[8]。出口[East]=0;
[8]号房间,[南]出口=1;
房间[8]。出口[West]=0;
}
有符号整数GetDirection(无符号整数RN){
int-NextRoom=0;
无符号字符d;
printf(“键入您希望行驶方向的第一个字母”);
printf(“\n或键入q退出\n”);
d=_getch();
如果(d='n')NextRoom=Room[RN]。退出[North];
如果(d=='e')NextRoom=房间[RN]。退出[East];
如果(d=='s')NextRoom=房间[RN]。退出[South];
如果(d=='w')NextRoom=房间[RN]。出口[West];
如果(d='q')NextRoom=-1;
返回(NextRoom);
}
void descripbeexit(无符号整数RN){
printf(“\n它可用于:”);
如果(房间[RN]。退出[North]>0)printf(“\n North”);
如果(房间[RN]。出口[East]>0)printf(“\n East”);
如果(房间[RN]。退出[South]>0)printf(“\n South”);
如果(房间[RN]。出口[West]>0)printf(“\n West”);
}
无效描述符对象(无符号整数RN){
printf(“\n%s”,房间[RN]。说明);
}

C中的数组从0索引。您将数组定义为具有8个成员,因此有效索引为0-7。但你进入了房间[8]。没有这样的怪兽。

你试过调试你的程序以查看崩溃发生在哪里吗?数组在C中是零索引的,所以访问
房间[8]
是未定义的行为。这是一个真正没有意义的标题。请将其更改为与您的问题相匹配的内容。既然你还没有这样做,请拿着这本书读一读。