| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 659 人关注过本帖
标题:c语言建线性表出错。。。
取消只看楼主 加入收藏
追寻XT
Rank: 2
等 级:论坛游民
威 望:1
帖 子:37
专家分:32
注 册:2014-8-20
结帖率:83.33%
收藏
已结贴  问题点数:10 回复次数:1 
c语言建线性表出错。。。
程序代码:
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
#include<stdlib.h>

struct STU{
    char Name[20];
    int  Age;
    int  Score;
};
typedef struct STU stu;

struct LIST{
    stu   S[20];
    int   Length;
};
typedef struct LIST List;

void init(List* L){
    L=(List*)malloc(sizeof(List));
    //L->Length=0;
}

void Found_LIST(List L,stu S[]){
    int count;
    for(count=0;count<L.Length;count++){
    L.S[count]=S[count];
}
void Print_List(List L){
    printf("Account  Name  Age  Score\n");
    int i;
    for(i=0;i<L.Length;i++)
    printf("%4d%4d%4d%4d",i,L.S[i].Name,L.S[i].Age,L.S[i].Score);
}
void main(void){
    List L; stu S[3];    init(L);
    L.Length=3;
    strcpy(S[1].Name,"TOM");S[1].Age=20;S[1].Score=90;
    strcpy(S[2].Name,"Jane");S[2].Age=21;S[2].Score=80;
    strcpy(S[3].Name,"Mari");S[3].Age=20;S[3].Score=90;

    Found_LIST(L,S[3]);
    Print_List(L);
}
搜索更多相关主题的帖子: c语言 线性表 
2014-09-21 21:46
追寻XT
Rank: 2
等 级:论坛游民
威 望:1
帖 子:37
专家分:32
注 册:2014-8-20
收藏
得分:0 
我的原程序,是堆空间未释放,先用List定义了L,已经分配了空间,又用init()初始化L,又为L分配了堆空间,当init()返回主函数main(),堆空间就无法释放,造成内存泄露,运行出错。。。
2014-09-27 09:45
快速回复:c语言建线性表出错。。。
数据加载中...
 
   



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

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