user-0 提问: 程序运行错误 显示 “process exited with return value 3221225725”

回复:
user: user-1
content: 仅供参考：//在堆中开辟一个4×5的二维int数组 #include <stdio.h> #include <malloc.h> int **p; int i,j; void main() {     p=(int **)malloc(4*sizeof(int *));     if (NULL==p) return;     for (i=0;i<4;i++) {         p[i]=(int *)malloc(5*sizeof(int));         if (NULL==p[i]) return;     }     for (i=0;i<4;i++) {         for (j=0;j<5;j++) {             p[i][j]=i*5+j;         }     }     for (i=0;i<4;i++) {         for (j=0;j<5;j++) {             printf(" %2d",p[i][j]);         }         printf("\n");     }     for (i=0;i<4;i++) {         free(p[i]);     }     free(p); } //  0  1  2  3  4 //  5  6  7  8  9 // 10 11 12 13 14 // 15 16 17 18 19

user: user-2
content: 二重指针，看到你的malloc只用了一次，也就是只申请了行数，那么列数呢？这样会导致段错误。

user: user-3
content: 这种又不是啥错误，只是说你的程序返回值是3221225725，你检查下main函数有没有加返回值就好了吧

user: user-4
content: 3221225725是程序抛出段错误（如栈溢出、非法指针等）

user: user-5
content: int **network;      比如这个你初始化就有问题  参考  #include <stdio.h>   #include <stdlib.h>   int main()   {       int** a = (int**)malloc(sizeof(int*)*3);       int i=0, j=0;           for (i=0; i<3; i++)       {           a[i] = (int*)malloc(sizeof(int)*5);           for (j=0; j<5; j++)           {               *(*(a+i)+j)=j;           }       }                   for (i=0; i<3; i++)       {           for (j=0; j<5; j++)           {               printf("%d\t", *(*(a+i)+j));           }           printf("\n");       }                   delete[] a;       return 0;   }

user: user-0
content: 嗯~~贴一下我整个程序吧！ 调试好几天了，怎么都不能正常运行 #include<stdio.h> #include<time.h> #include<stdlib.h> #include <string.h> #include<math.h> #include<float.h> /*  *两层网络都为BA，Na=Nb=N/2=1000 *<ka>=<kb>=<k>=10 *C=5 *耦合强度β *intra—traffic 最短路                    1- P *inter—traffic global shortest           p *每层网络产生R个信息包  */  int INF=0;  int C=5,R,Size,Size2,Origin_packets=50000; int **network; int *node_array; /*节点信息包数目*/ int *node_move;  /*节点发送信息包数目*/  FILE *fp;  typedef struct {              /*信息包*/  	int node; 	int destination; 	int place_in_node; }Packet,Packetptr;  Packet *packet;  void initial(); void file(); void connect();  int main()  {  	 	int time_step; 	int sum_step=10000; 	int node,P_node; 	double min=0; 	int Sum_S=0; 	int i,j,k,n; 	int rand1,rand2,sum_packets=0;  	INF=Size2*Size2; 	printf("Size="); 	scanf("%d",&Size); 	printf("R="); 	scanf("%d",&R); 	Size2=2*Size; 	srand((unsigned)time(NULL)); 	 	initial();      file();     /*connect();     */     int **path = (int**)malloc(sizeof(int*)*Size2); 	for(i=0; i<Size2; i++){ 		for(j=0; j<Size2; j++){ 			path[i][j]=0; 		} 	} 	 	/*Djistra算法找路*/ 	    /*关键在于寻找前置节点*/  	    /*flag[i]=0说明点在集合S中，即该点与起点间的最短路径已找到*/  	    int *flag = (int*)malloc(sizeof(int)*Size2); 	    int *T_array = (int*)malloc(sizeof(int)*Size2); 	    int *tmp_T_array = (int*)malloc(sizeof(int)*Size2); 	    int *node_T_array = (int*)malloc(sizeof(int)*Size2);/*node_T_array为前置节点*/  	    int **weight=(int**)malloc(sizeof(int)*Size2); 	    /*对边赋权*/  		/*不相连的节点为INF，相连=1*/  		/*for(i=0; i<Size2; i++){                               			for(j=0; j<Size2; j++){ 				if(network[i][j] == 1)   				    weight[i][j] = 1; 				else  					weight[i][j] = INF; 			} 		} 		*/ 		/*初始化每个节点的数值*/ 		for(i=0; i<Size2; i++){ 			flag[i] = 0; 			T_array[i] = 0; 			tmp_T_array[i] = 0; 		    node_T_array[i]=0;	 		} 		/*寻找所有点为起点的最短路*/  		for(node=0; node<Size2; node++){            			/*每一次换起点，都重置数值*/ 			for(i=0; i<Size2; i++){                 				T_array[i]=(double)INF; 				tmp_T_array[i]=(double)INF; 				flag[i]=0; 			} 			/*起点T、tmp_T都为0，且在集合S中*/  			T_array[node]=0; 			tmp_T_array[node]=0; 			flag[node]=1; 			node_T_array[node]=node; 			 			P_node=node; 			/*Sum_S=Size2则说明所有节点的最短路已找到*/  			Sum_S=1; 			do{ 				/*确定相邻点的T标号*/  				for(i=0; i<Size2; i++){ 					if(flag[i] == 0 && network[P_node][i] == 1){ 						tmp_T_array[i] = T_array[P_node] + 1; 						if(tmp_T_array[i] < T_array[i]){ 							T_array[i] = tmp_T_array[i]; 							node_T_array[i] = P_node; 						} 					} 				} 				 				/*寻找所有T标号中最小的*/  				min = (double)INF; 				for(i=0; i<Size2; i++){ 					if(min > T_array[i] && flag[i] == 0){ 						min = T_array[i]; 						P_node = i; 					} 				} 				 				flag[P_node] = 1; 				path[P_node][node] = node_T_array[P_node]; 				 				Sum_S++; 			}while(Sum_S != Size2); 		} 		 	/*加包，找路， 传包*/  	for(time_step=0; time_step<sum_step; time_step++) {                    	    int i,j,k,n; 	    for(i=0; i<R; i++){ 	       do{                                /*随机选择出发点与到达点*/  	   	        rand1 = rand()%Size2; 	            rand2 = rand()%Size2; 	        }while(rand1 == rand2);  	       do{                                /*选一个信息包*/ 	   	        k= rand()%Origin_packets; 	         }while(packet[k].node>=0); 	        packet[k].node=rand1; 	        packet[k].destination=rand2; 	        node_array[rand1]++; 	        packet[k].place_in_node=node_array[rand1]; 	    }                                            	     	     	/*传包*/ 	    for(i=0; i<Origin_packets; i++){ 		   if(packet[i].node >= 0 && packet[i].place_in_node <= C) { 		   	    node_move[packet[i].node]++; 		   	    packet[i].node = path[packet[i].destination][packet[i].node]; 		   } 		   if(packet[i].node = packet[i].destination){         /*信息包到达目的地*/  	            packet[i].node = -1; 			} 		   if(packet[i].node != packet[i].destination){ 				node_array[packet[i].node]++; 				packet[i].place_in_node = node_array[packet[i].node]; 			} 	    } 		 		/*调整packet在node中的位置*/  		for(i=0; i<Origin_packets; i++){ 			if(packet[i].node >= 0){ 				packet[i].place_in_node = packet[i].place_in_node - node_move[packet[i].node]; 			} 		} 		 		/*调整node中的包数*/ 		for(i=0; i<Size2; i++){ 			node_array[i] -= node_move[i]; 			node_move[i] = 0; 		} 		 		if(time_step%10==0) 		{ 			sum_packets=0; 			for(i=0; i<Size2; i++) 			{ 				sum_packets += node_array[i]; 			} 			printf("%d %d\n",time_step,sum_packets); 			fprintf(fp,"sum_packet\n",sum_packets);	 		}		     }     return 0; }	    void initial() { 	int i,j; 	node_array=(int*)malloc(sizeof(int)*Size2); 	node_move=(int*)malloc(sizeof(int)*Size2); 	network=(int**)malloc(sizeof(int*)*Size2); 	for(i=0; i<Size2; i++){ 		node_array[i]=0;          		node_move[i]=0;          	} 	packet=(Packetptr*)malloc(sizeof(Packet)*Origin_packets); 	for(i=0; i<Origin_packets; i++){                                /*信息包在节点外*/  		packet[i].node=-1; 		packet[i].destination=-1; 		packet[i].place_in_node=0; 	}  	 }   void file() {                                        /*输入文件*/  	int i,j; 	for(i=0; i<Size2; i++){ 		for(j=0; j<Size2; j++){ 			network[i][j]=0; 		} 	} 	FILE *fp1, *fp2; 	if((fp1=fopen("BA1.txt","r"))==NULL){ 		printf("can open BA1 \n"); 		exit(0); 	} 	for(i=0; i<Size; i++){ 		for(j=0; j<Size; j++){ 			fscanf(fp1,"%d",&network[i][j]);        /*从文件中读取网络BA1       Upper_network*/   	    } 	    fscanf(fp1,"\n");     }     fclose(fp1);     if((fp2=fopen("BA2.txt","r"))==NULL){ 		printf("can open BA2 \n"); 		exit(0); 	} 	for(i=Size; i<Size2; i++){ 		for(j=Size; j<Size2; j++){ 			fscanf(fp2,"%d",&network[i][j]);        /*从文件中读取网络BA2       Lower_network*/  	    } 	    fscanf(fp2,"\n");     }     fclose(fp2);     /*for(i=0; i<Size; i++) {     	for(j=Size; j<Size2; j++) {     		network[i][j]=0;     		network[j][i]=0; 		}     }  	*/ }  /* void connect() { 	int i,j,a; 	double B; 	int *Upper_degree; 	int *Lower_degree; 	Upper_degree=(int*)malloc(sizeof(int)*Size); 	Lower_degree=(int*)malloc(sizeof(int)*Size); 	for(i=0; i<Size; i++){ 		Upper_degree[i] = 0; 		Lower_degree[i] = 0; 	} 	for(i=0; i<Size; i++){ 	    for(j=0; j<Size; j++) { 	    	Upper_degree[i] += network[i][j];  	    	Lower_degree[i] += network[i+Size][j+Size]; 		} 	} 	 	/////////////按度大小排序////////////// 	int *sort1; 	int *sort2; 	sort1=(int*)malloc(sizeof(int)*Size); 	sort2=(int*)malloc(sizeof(int)*Size); 	 	for(i=0; i<Size ;i++){ 		sort1[i]=0; 		sort2[i]=0; 	}      for(j=0; j<Size; j++){ 		for(i=j+1; i<Size; i++){ 			if(Upper_degree[j]<=Upper_degree[i]){ 			    sort1[j]=i; 			    a=Upper_degree[j]; 				Upper_degree[j]=Upper_degree[i]; 				Upper_degree[i]=a; 			} 		} 	}  	for(j=0; j<Size; j++){ 		for(i=j+1; i<Size; i++){ 			if(Lower_degree[j]<=Lower_degree[i]){ 			    sort2[j]=i+Size;                            /*上层为0~999，下层为1000~1999*/  /*			    a=Lower_degree[j]; 				Lower_degree[j]=Lower_degree[i]; 				Lower_degree[i]=a; 			} 		} 	}  	///////////////sort////////////////// 	 	//////////////connect///////////////协同耦合//////////////  	int Num_connect = B*Size; 	for(i=0; i<Num_connect; i++){ 		network[sort1[i]][sort2[i]]=network[sort2[i]][sort1[i]]=1; 	} } */