|
このプログラムはBorland C++ Compiler 5.5だと動くのですが
Microsoft Visual C++6.0だと動きません。
どこがいけないのか教えてください。
#include<stdio.h>
#include<stdlib.h>
const int N=14;
const int M=30;
typedef struct PARTICLE{
double data_x;
double data_y;
double v_x;
double v_y;
double mass;
int position;
struct PARTICLE *next;
struct PARTICLE *subnext;
}Particle;
typedef struct NodeData{
struct PARTICLE *pfirst;
double xc;
double yc;
double mass;
int position;
struct NodeData *child[4];
int nparticle;
double length;
int k;
}Node;
double **make_matrix(int N,int M)
{
int i;
double **matrix;
matrix=(double **)calloc(N,sizeof(double*));
if(matrix==NULL){
printf("memory is now using");
exit(EXIT_FAILURE);
}
for(i=0;i<N;i++){
matrix[i]=(double *)calloc(M,sizeof(double));
if(matrix[i]==NULL){
printf("memory is now using");
exit(1);
}
}
return matrix;
}
Node *make_structmatrix(int N)
{
Node *matrix;
matrix=(Node *)malloc(sizeof(Node)*N);
if(matrix==NULL)
{
printf("memory is now using");
exit(1);
}
return matrix;
}
Particle *make_struct(int N)
{
Particle *matrix;
matrix=(Particle *)malloc(sizeof(Particle)*N);
if(matrix==NULL)
{
printf("memory is now using");
exit(1);
}
return matrix;
}
void make_list(Particle *p,double **dat,Node *root)
{
int i;
root->xc=8.0;
root->yc=8.0;
p->data_x=dat[0][0];
p->data_y=dat[0][1];
p->v_x=0;
p->v_x=0;
root->pfirst=p;
for(i=1;i<N;i++){
(p+i)->data_x=dat[i][0];
(p+i)->data_y=dat[i][1];
(p+i)->v_x=0.0;
(p+i)->v_y=0.0;
(p+i)->mass=1.0;
(p+i)->position=0;
(p+i-1)->next=(p+i);
}
(p+N)->next=NULL;
}
main()
{
int i,k;
double **dat;
double x,y;
int remain,top;
double a[8]={-1.0,-1.0,1.0,-1.0,-1.0,1.0,1.0,1.0};
Particle *p,*the;
Node *b,*root;
FILE *fp;
remain=M-1;
top=1;
dat=make_matrix(N,4);
b=make_structmatrix(M);
p=make_struct(N);
fp=fopen("Nobody.txt","r");
if(fp==NULL)
{
printf("Don't exist 'Nobody.txt\n'");
exit(0);
}
k=0;
while(fscanf(fp,"%lf %lf",&x,&y)!=EOF)
{
dat[k][0]=x;
dat[k][1]=y;
dat[k][2]=0.0;
dat[k][3]=0.0;
k++;
}
root=b;
make_list(p,dat,root);
for(the=root->pfirst;the!=NULL;the=the->next)
{
printf("%lf %lf\n",the->data_x,the->data_y);
}
free(dat);
free(b);
free(p);
fclose(fp);
return 0;
}
|