小编Yxu*_*uer的帖子

C忽略"if"指令

我最近做的一个程序有问题.基本上,这是John Conway的生活游戏的简单版本,但它不能正常工作.问题出在代码中,它读取单元格及其邻居的状态并决定该单元格的未来状态.这是代码的一部分(它有点长):

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

//Game grid size
#define SIZE 15

//Cell state (wall is a special state. It protects the other cells from garbage data of the heap memory)
enum cellState {dead,alive,wall};

//Function prototypes
int** load(int**);
void process(int**);

int main(){

    //Game grid (2-D matrix) and its memory allocation
    int** grid;

    grid=(int**)calloc(SIZE+2,sizeof(int*));
    for(int cont=0;cont<SIZE+2;cont++){
        *(grid+cont)=(int*)calloc(SIZE+2,sizeof(int));
    }

    load(grid);
    getch();
    process(grid);
    getch();
}

//Grid loading function
int** load(int** grid){

    int type;
    srand(12345);
    for(int cont=0;cont<SIZE+2;cont++){
        for(int cont2=0;cont2<SIZE+2;cont2++){
            if(cont==0||cont==TAMANO+1||cont2==0||cont2==TAMANO+1){
                *(*(grid+cont)+cont2)=wall;
            }
            else{
                //Cell type decision …
Run Code Online (Sandbox Code Playgroud)

c

1
推荐指数
1
解决办法
140
查看次数

标签 统计

c ×1