之前在devc++编码的程序打不开了

img


不知道是不是我在第一次程序的基础上改了很多次的原因。
好奇怪啊,感觉devc++经常出现我意想不到的错误,

【相关推荐】



  • 这个问题的回答你可以参考下: https://ask.csdn.net/questions/7788470
  • 这篇博客也不错, 你可以看下关于DevC++如何调试的问题,还不会调试的同学看这里--->>>超级详细调试教程,手把手教你如何调试
  • 除此之外, 这篇博客: 首次适应算法 动态分区分配方式的模拟 C语言——课程设计实习中的 C语言源程序——建议使用Devc ++ 运行 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
    #include<stdio.h>
    #include<stdlib.h>
    struct nodespace{
    	int teskid;   // 作业号 
    	int begin;    // 开始地址 
    	int size;     // 大小 
    	int status;   // 状态 0代表占用,1代表空闲 
    	struct nodespace *next;  // 后指针 
    };
    void initNode(struct nodespace *p){
    	if(p == NULL){	//如果为空则新创建一个 
    		p = (struct nodespace*)malloc(sizeof(struct nodespace));
    	}
    	p->teskid = -1;
    	p->begin = 0;
    	p->size = 640;
    	p->status = 1;
    	p->next =NULL; 
    }  
    void myMalloc1(int teskid,int size,struct nodespace *node){
    	while(node != NULL){
    		if(node->status == 1){  //空闲的空间 
    			if(node->size > size){  //当需求小于剩余空间充足的情况 
    				//分配后剩余的空间 
    				struct nodespace *p = (struct nodespace*)malloc(sizeof(struct nodespace));
    				p->begin = node->begin + size;
    				p->size = node->size - size;
    				p->status = 1;
    				p->teskid = -1;
    				//分配的空间 
    				node->teskid = teskid; 
    				node->size = size;
    				node->status = 0;
    				//改变节点的连接 
    				p->next = node->next; 
    				node->next = p;
    				printf("==================================分配内存成功!==================================\n");
    				break; 
    			}else if(node->size == size){ //需求空间和空闲空间大小相等时 
    				node->teskid = teskid; 
    				node->size = size;
    				node->status = 0;
    				printf("==================================分配内存成功!==================================\n");
    				break;
    			}	
    		}
    		if(node->next == NULL){
    			printf("===============================分配失败,没有足够的空间!=============================\n");
    			break;
    		}
    		node = node->next;
    	}
    } 
    void myFree(int teskid,struct nodespace *node){
    	if(node->next == NULL && node->teskid == -1){
    		printf("================================您还没有分配任何作业!================================\n");
    	}
    	
    	while(node != NULL){
    		if(node->status == 1 && node->next->status ==0 && node->next->teskid == teskid){
    			
    			struct nodespace *q = node->next;
    			node->next = node->next->next;
    			free(q);
    			printf("==================================释放内存成功!==================================\n");
    			if(node->next->status == 1){ //下一个空间是空闲空间时 
    				node->size = node->size + node->next->size;
    				struct nodespace *q = node->next;
    				node->next = node->next->next;
    				free(q);
    				printf("==================================释放内存成功!==================================\n");
    			}
    			break;
    		}else if(node->status == 0 && node->teskid == teskid){  //释放空间和空闲空间不连续时  
    			node->status = 1;
    			node->teskid = -1;
    			if(node->next != NULL && node->next->status == 1){ //下一个空间是空闲空间时 
    				node->size = node->size + node->next->size;
    				struct nodespace *q = node->next;
    				node->next = node->next->next;
    				free(q);
    			}
    			printf("==================================释放内存成功!==================================\n");
    			break;
    		}else if(node->next == NULL){  //作业号不匹配时 
    			printf("==================================没有此作业!!==================================\n");
    			break;
    		}
    		node = node->next;
    	}
    	
    	 
    } 
    void printNode(struct nodespace *node){
    	printf("                        内存情况                        \n"); 
    	printf(" -------------------------------------------------------\n");
    	printf("| 起始地址\t结束地址\t大小\t状态\t作业号\t|\n");
    	while(node != NULL){
    		if(node->status==1){
    			printf("| %d\t\t%d\t\t%dKB\tfree\t 无\t|\n", node->begin + 1, node->begin+node->size, node->size);
    		}else{
    			printf("| %d\t\t%d\t\t%dKB\tbusy\t %d\t|\n", node->begin + 1, node->begin+node->size, node->size, node->teskid);
    		}
    		node = node->next;
    	}
    	printf(" -------------------------------------------------------\n");
    }
    void destory(struct nodespace *node){
    	struct nodespace *q = node;
    	while(node != NULL){
    		node = node->next;
    		free(q);
    		q = node;
    	}
    } 
    void menu(){
    	printf("\n"); 
    	printf("\t\t\t\t   ╭═════════════════════════════════○●○●═══╮\n");
    		printf("\t\t\t\t   │    首次适应算法的动态分区分配方式模拟      │\n");
    		printf("\t\t\t\t   ╰═══○●○●═════════════════════════════════╯\n");
    		printf("\t\t\t\t   ┌───────────────────────────────────────────-┐\n");
    		printf("\t\t\t\t   │                                            │\n");
    		printf("\t\t\t\t   │                 1. 申请内存                │\n");
    		printf("\t\t\t\t   │                                            │\n");
    		printf("\t\t\t\t   │                 2. 回收内存                │\n");
    		printf("\t\t\t\t   │                                            │\n");
    		printf("\t\t\t\t   │                 3. 查看内存情况            │\n");
    		printf("\t\t\t\t   │                                            │\n");
    		printf("\t\t\t\t   │                 4. 退出                    │\n");
    		printf("\t\t\t\t   │                                            │\n");
    		printf("\t\t\t\t   └────────────────────────────────────────────┘\n");
    		printf("\t\t\t\t\t\t  请您选择(1-4):\t");
    }
     
    int main(){
    	// node为整个空间 
    	system("color 0f");
    	//system("mode con cols=120 lines=50");
    	struct nodespace *init = (struct nodespace*)malloc(sizeof(struct nodespace));
    	struct nodespace *node = NULL;
    	initNode(init);			//初始化主链 
    	node = init; 			//指向链表头 
    	int option; 
    	int teskid;
    	int size;
    	while(1){
    		menu();		//打印想要进行的操作
    		scanf("%d",&option);
    		if(option == 1){
    			printf("请输入作业号;");
    			scanf("%d",&teskid);
    			printf("此作业申请的空间大小(KB):");
    			scanf("%d",&size);
    			myMalloc1(teskid,size,node);
    			printf("\n"); 
    			printNode(node);
    		}else if(option == 2){
    			printf("请输入作业号:");
    			scanf("%d",&teskid);
    			myFree(teskid,node);
    			printf("\n"); 
    			printNode(node);
    		}else if(option == 3){
    			printNode(node);
    		}else if(option == 4){
    			destory(node);
    			initNode(init);
    			node = init;
    			break;
    		}else{
    			printf("===========================您的输入有误,请重新输入!============================\n");
    			continue;
    		}
    	}
    return 0;
    }
    

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^