标题:这个程序哪里错了。如何变?
只看楼主
我是岳阳人
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2004-8-13
 问题点数:0 回复次数:2 
这个程序哪里错了。如何变?
#include "stdlib.h"

#include "stdio.h"

#define M 50

#define N 10

getdata (int *s)

{ int i;

for(i=0; i<M; i++) s=random(10);

}

stat(int *a,int *c)

{ int i;

for(i=0;i<N; i++) c=0;

for(i=0;i<M; i++) c[a]++;

}

outdata (int *c)

{int i;

for (i=0;i<N; i++) printf("%d : %d\n",i,c);

}

main()

{ int a[M],c[N];

getdata (a);

stat(a,c);

printf("Output the result: \n");

outdata(c);

}

出现了“rror C2065: 'random' : undeclared identifier“



4iBxndxm.jpg (19.34 KB)
2004-08-14 11:45
天地一沙鸥
Rank: 1
等 级:新手上路
帖 子:58
专家分:0
注 册:2004-8-14
得分:0 

哦哦哦,~我也不清楚,希望有人能告诉我


鸟凄声以孤归, 兽索偶而不还。 悼当年之晚暮, 恨兹岁之欲殚。 思宵梦以从之, XXX而不安; 若凭舟之失棹, 譬缘崖而无攀。 /img/assets/200401/200401061015134010607.jpg" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://joke.tom.com/img/assets/200401/200401061015134010607.jpg');}" onmousewheel="return imgzoom(this);" alt="" />
2004-08-14 13:44
TARGET_MG42
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2004-8-7
得分:0 

程序可以运行!

但是有警告:

子函数前应该有返回类型;还有random返回的是int型,而s是整型指针,整型指针不能直接赋给整型数,除非强制类型转换!

不过,我估计你上面的问题在于编译器,可能没有stdlib.h 头文件,或者在stdlib.h头文件中没有定义random()函数!你试试 用另一个随机函数rand()%num!

2004-08-15 09:57
  • 3
  • 1/1页
  • 1



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-4245-1-1.html




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

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