| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5034 人关注过本帖
标题:诸神请看:第二次调用malloc给结构指针分配空间时出错 0xC0000374: 堆已损坏 ...
只看楼主 加入收藏
zwdbxlt
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2015-1-1
收藏
得分:0 
回复 10楼 TonyDeng
谢谢您回复我的帖子,谢谢您的时间,正是您的回复,才使我不断地提高。
2015-02-21 12:09
pycansi
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:5
帖 子:418
专家分:1060
注 册:2012-7-26
收藏
得分:10 
兄台知道问题何在吗?
可否以一段简短代码展示出问题?


莫问前尘有愧,但求今生无悔
2015-02-22 10:27
zwdbxlt
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2015-1-1
收藏
得分:0 
回复 12楼 pycansi
问题我还没找到,我用其他方式代替了,我写了一个包含这个错误的很简单的程序,你可以试着找找原因,找到了请告诉我一声,非常感谢。
#include<stdio.h>
#include <ctype.h>
#define MAXLEN 1000
#include <string.h>
#include <stdlib.h>

struct node {
    int biaozhi;
    char *p;
    struct node *zuo;
    struct node *you;
};
int shuzhuangfuzhi(struct node *, char *word);
int main()
{
    struct node *p = NULL;
    int  c = 0,i=0;
    char word[MAXLEN];
    char *fuzhi[MAXLEN] = {"hello","man",NULL};
    while (fuzhi[i]!=NULL)
    {
    p = shuzhuangfuzhi(p, fuzhi[i++]);
    }

    system("pause");
}


struct node *talloc(void);
char *strup(char *);

int shuzhuangfuzhi(struct node *p, char *word)
{
    int a;
    if (p == NULL)
    {

        p = talloc();
        p->biaozhi = 0;
        p->p = strup(word);
        p->zuo = NULL;
        p->you = NULL;
    }
    else
        shuzhuangfuzhi(p->zuo, word);
    return p;
}

struct node *talloc(void)
{
    return (struct node *) malloc(sizeof(struct node));
}


char *strup(char *s)
{
    char *p;
    p = (char *)malloc(strlen(s) + 1);
    if (p != NULL)
        strcpy_s(p, 50, s);
    return p;
}
2015-02-22 23:25
pycansi
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:5
帖 子:418
专家分:1060
注 册:2012-7-26
收藏
得分:0 
我在Pelles C中运行这段代码(加了两处强制类型转换),没有报错e..


莫问前尘有愧,但求今生无悔
2015-02-23 20:45
快速回复:诸神请看:第二次调用malloc给结构指针分配空间时出错 0xC0000374: 堆 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023877 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved