| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 568 人关注过本帖
标题:为什么没有结果呀?
只看楼主 加入收藏
wwiilla
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2005-9-5
收藏
 问题点数:0 回复次数:7 
为什么没有结果呀?

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

#define LIST_INIT_SIZE 32
#define LISTINCREMENT 10

struct Stu {
float chinese;
float english;
float database;
float math;
};


typedef struct {
Stu *elem;
int length;
int listsize;
}StuList;

void ScanScore( Stu &L ) {
printf("chinexe:");
scanf("%f",&L.chinese);
printf("\nenglish:");
scanf("%f",&L.english);
printf("\ndatabase:");
scanf("%f",&L.database);
printf("\nmath:");
scanf("%f",&L.math);
printf("\n");
}


int InitList_Stu ( StuList &L ) {
L.elem = ( Stu * )malloc( LIST_INIT_SIZE * sizeof( Stu ));
if( !L.elem ) exit( -2 );
L.length = 0;
L.listsize = LIST_INIT_SIZE;
return 1;
}
int main ()
{
Stu a ;
ScanScore( a );
StuList b;
b.elem = &a;
printf("%f",b.elem);
free( b.elem );
return 1;
}

搜索更多相关主题的帖子: 结果 
2006-05-10 22:58
gaga
Rank: 1
等 级:新手上路
威 望:2
帖 子:307
专家分:0
注 册:2006-4-5
收藏
得分:0 
以下是引用wwiilla在2006-5-10 22:58:00的发言:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

#define LIST_INIT_SIZE 32
#define LISTINCREMENT 10

struct Stu {
float chinese;
float english;
float database;
float math;
};


typedef struct {
Stu *elem;
int length;
int listsize;
}StuList;

void ScanScore( Stu &L ) {
printf("chinexe:");
scanf("%f",&L.chinese);
printf("\nenglish:");
scanf("%f",&L.english);
printf("\ndatabase:");
scanf("%f",&L.database);
printf("\nmath:");
scanf("%f",&L.math);
printf("\n");
}


int InitList_Stu ( StuList &L ) {
L.elem = ( Stu * )malloc( LIST_INIT_SIZE * sizeof( Stu ));
if( !L.elem ) exit( -2 );
L.length = 0;
L.listsize = LIST_INIT_SIZE;
return 1;
}
int main ()
{
Stu a ;
ScanScore( a );
StuList b;
b.elem = &a;
printf("%f",b.elem);
free( b.elem );
return 0;注意主涵数返回的值是什么


}


明天的明天还有明天。 可是今天却只有一个。 public Copy from 无缘今生
2006-05-10 23:32
wwiilla
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2005-9-5
收藏
得分:0 

肯不是这个问题了..

2006-05-11 12:02
gaga
Rank: 1
等 级:新手上路
威 望:2
帖 子:307
专家分:0
注 册:2006-4-5
收藏
得分:0 
int main ()
{
Stu a ;
ScanScore( a );
StuList b;
InitList_Stu ( b)/*你都没有进行初始分配内存*/
b.elem = &a;
printf("%f",b.elem);/*不知道你这是在干什么都没有一个终止标准最好加个*/
free( b.elem );
return 0;
}

[此贴子已经被作者于2006-5-11 18:22:18编辑过]


明天的明天还有明天。 可是今天却只有一个。 public Copy from 无缘今生
2006-05-11 18:09
gaga
Rank: 1
等 级:新手上路
威 望:2
帖 子:307
专家分:0
注 册:2006-4-5
收藏
得分:0 

算了
具体的我也改不了
还是等高手吧

上面的问题就很成问题了


明天的明天还有明天。 可是今天却只有一个。 public Copy from 无缘今生
2006-05-11 18:38
菜鸟上路
Rank: 4
等 级:贵宾
威 望:14
帖 子:1120
专家分:0
注 册:2006-3-21
收藏
得分:0 

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

#define LIST_INIT_SIZE 32
#define LISTINCREMENT 10

typedef struct Stu {
float chinese;
float english;
float database;
float math;
}Stu;


typedef struct {
Stu *elem;
int length;
int listsize;
}StuList;

void ScanScore( Stu *L )
{

printf("Chinese:");
scanf("%f",&L->chinese);
printf("\nEnglish:");
scanf("%f",&L->english);
printf("\nDatabase:");
scanf("%f",&L->database);
printf("\nMath:");
scanf("%f",&L->math);
printf("\n");
}


InitList_Stu ( StuList *L )
{
L->elem = ( Stu * )malloc(sizeof( Stu ));
if( !L->elem ) exit( -2 );
L->length = 0;
L->listsize = LIST_INIT_SIZE;
ScanScore(L->elem);
}
main ()
{
Stu *a ;
StuList *l;
l = (StuList *)malloc(sizeof(StuList));
InitList_Stu (l);

getch();

}
改了一下,但是屏幕只是闪了一下
请问下谁知道


2006-05-11 19:47
白水
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2006-5-4
收藏
得分:0 
void ScanScore( Stu &L ) {
float a;
printf("chinexe:");
scanf("%f",&a);
L.chinese=a;
printf("english:");


呵呵 这样就可以了

去掉free这个函数可以运行。。
有能讲下free这个函数的么

[此贴子已经被作者于2006-5-11 21:06:37编辑过]

2006-05-11 20:40
菜鸟上路
Rank: 4
等 级:贵宾
威 望:14
帖 子:1120
专家分:0
注 册:2006-3-21
收藏
得分:0 

按楼上的改应该得不到正确的运行结果吧


2006-05-11 21:18
快速回复:为什么没有结果呀?
数据加载中...
 
   



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

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