c语言可变长数组函数用法,关于vc6.0使用可变长数组的一些问题

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

// 1.cpp : Defines the entry point for the

console application.//

#include

#include

#include

#include

#include "stdafx.h"

int main(int argc, char* argv[])

{

int n,i=0,l=0;

int N;

int sum,k=1;

printf("Enter the size of the game:");

scanf("%d",&n)

printf("\n");

int **home;

home=(int**)malloc(n*sizeof(**home));

for(i=0;i

{

home[i]=(int*)malloc(n*sizeof(*home));

for(l=0;l

{

home[i][l]=0;

}

}

int **tmp;

tmp=(int**)malloc((n+2)*sizeof(**tmp));

for(i=0;i

{

tmp[i]=(int*)malloc((n+2)*sizeof(*tmp));

for(l=0;l

{

tmp[i][l]=0;

}

}

printf("Enter the time of the game:");

scanf("%d",&N);

printf("\n");

printf("Enter the start state:");

scanf("%d",&home[i][l]);

for(k=1;k

{

for(inti=1;i<=100;i++)

{

for(int l=1;l<=100;l++)

{

sum=home[i+1][l]+home[i+1][l-1]+home[i][l-1]+home[i-1][l-1]+home[i-1][l]+home[i-1][l+1]+home[i][l+1]+home[i+1][l+1];

switch(sum)

{

case 3:

tmp[i][l]=1;

break;

case 2:

tmp[i][l]=home[i][l];

break;

default:

tmp[i][l]=0;

break;

}

printf("%d",tmp[i][l]);

}

printf("\n");

}

memcpy(home,tmp,(n+2)*(n+2)*sizeof(**tmp));

printf("next\n");

}

free(home);

free(tmp);

return 0;

}

我是打算编一个生命游戏的程序,空间(二维数组)的大小由外界给,运行的时间由外界给。现在问题基本解决了,就是在调试的时候会出现问题,说该程序已停止工作。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值