由买买提看人间百态

topics

全部话题 - 话题: stdlib
首页 上页 1 2 3 4 5 下页 末页 (共5页)
l******e
发帖数: 470
1
#include
#include
#include
#include
#include
#include
using namespace std;
float surand() //gene uni dis [0,1]
{
return( (float) rand()/RAND_MAX );
}
float urand(float low, float high) //gene uni dis[low,high]
{
return(low+(high-low)*surand());
}
float genexp(float lambda) //generate exp dist
{
float u,x;
u=surand();
x=(-1/lambda)*log(u);
return(x);
}
float gennor(float mean, float stanvar) //gene norm dis with mean and
standard va
b******u
发帖数: 469
2
奇怪,我vs6做的,输出都是0.x。不知道为啥
#include
#include
void main()
{
for (int nn=0;nn<500;nn++)
{
float zz = ((float)(rand()%10))/10;
cout< }
}
n********s
发帖数: 144
3

提取两标点符号之间的两个汉语词,如“你 好”,或者如。有 什么,

结果老错,应该是汉字正则表达式有问题,麻烦帮忙看一下:


%{
#include
#include
#include
#include
#include
%}

%%
[\u3001-\u303F]+[\u3000]*[\u2E80-\u2EFF\u2F00-\u2FDF\u31C0-\u31EF\u3200-\
u32FF\u3300-\u33FF\u3400-\u4DBF\u4DC0-\u4DFF\u4E00-\u9FBF\uF900-\uFAFF\uFE30
-\uFE4F\uFF00-\uFFEF]+[\u3000]+[\u2E80-\u2EFF\u2F00-\u2FDF\u31C0-\u31EF\
u3200-\u32FF\u3300-\u33FF\u3400-\u4DBF\u4DC0-\u4DFF\u4E00-\u9FBF\uF900-\
uFAFF\uFE30-\uFE4F\uFF00-\u... 阅读全帖
j**********i
发帖数: 3758
4
来自主题: CS版 - vostro 230=银河1?2
http://baike.baidu.com/view/3691487.htm
#include
#include
#include
#include
#include
#include
int main()
{
float m_fTimeElapsed;
int j;
long double x;
LARGE_INTEGER m_timeFreq;
LARGE_INTEGER m_timeStart;
LARGE_INTEGER m_timeStop;
QueryPerformanceFrequency(&m_timeFreq);
QueryPerformanceCounter(&m_timeStart);
for(int i=0;i<4000000000;i++){
j=i+1;
// x=(long double)sin(i*3... 阅读全帖
f*********0
发帖数: 861
5
来自主题: CS版 - 帮忙debug这个C程序,谢谢!
快崩溃了, 怎么也run不起来, 不知道哪里有问题.
#include
#include
int main()
{
float grade1;
float grade2;
float grade3;
printf("enter your 3 test grades: n");
scanf(" %fn", &grade1);
scanf(" %fn", &grade2);
scanf(" %fn", &grade3);
float avg =(grade1 + grade2 + grade3)/3;
printf("average: %.2fn", avg);
if(avg >=90){
printf("grade: A");
}else if(avg >=80){
printf("grade: B");
}else if(avg >=70){
printf("grade: C");
}else if(avg >=60){
printf("grade: D");
}else{
printf("you are fai... 阅读全帖
r**i
发帖数: 2328
6
来自主题: Java版 - Calling Java from C/C++
I used to call C/C++ methods from Java side, now I want to use JNI to call
Java methods from C/C++. The code segment is like below:
#include
#include
#include
#ifdef _WIN32
#define PATH_SEPARATOR ';'
#else
#define PATH_SEPARATOR ':'
#endif
int main()
{
JavaVMOption options[1];
JavaVM *jvm;
JavaVMInitArgs vm_args;
long status;
JNIEnv *env;
jclass cls;
jmethodID mid;
jint square;
jboolean not;
options[0].optionString = "-Djava.class.path=.";
//memset(&vm_args, 0, size
z*******3
发帖数: 13709
7
来自主题: Java版 - 本菜对EJB一问
研究了一下minecraft的客户端
发现还是要自己去倒腾一下
对于linux来说,不用写任何东西,直接执行.jar,默认是四分之一内存
如果是windows,我用c写了一个小程序,.exe
#include "stdlib.h"
main(){
system("java -Xms128m -Xmx128m -jar myApp.jar");
}
现在问题是macosx下怎么办?
我看minecraft用的是.app,这个貌似要用到xcode?
谁知道的给解答解答该怎么操作
尤其是如何调用系统的命令java -version这种
包子酬谢
i*****f
发帖数: 578
8
来自主题: Linux版 - 关于signal handler
raise() just send a signal to itself. I think the codes below raise() will
continue to be executed. See man 3 raise. Also, try the following code:
#include
#include
#include
/* A handler for the ALARM signal */
void act_sigalrm(int sig)
{
puts("catched a SIGALRM");
/* raise this signal again. */
raise(sig);
puts("this code will be executed.");
}
int main()
{
signal(SIGALRM, act_sigalrm);
/* issue SIGALRM 3 sec later */
alarm(3);
/* entering event l
r****y
发帖数: 26819
9
来自主题: Linux版 - 看看这个 C 代码
not exactly original but can simulate:
/*
* sizeof.c - Implementation of sizeof operator
* http://faq.zanvar.in
*/
#include
#include
/* Find the size of an variable */
#define sizeof_var( var ) ((size_t)(&(var)+1)-(size_t)(&(var)))
/* Find the size of a data type */
#define sizeof_type( type ) (size_t)((type*)1000 + 1 )-(size_t)((type*)1000)
int main ( void )
{
int a;
int b[10];
printf ( "%lu\n", sizeof ( b ) );
printf ( "%lu\n", sizeof ( b+0 ) );
printf ( "%lu\n", sizeof_va
r*******y
发帖数: 1081
10
来自主题: Linux版 - 看看这个 C 代码
seems a good solution. but in which header files?
I tried stdlib.h, malloc.h. But did not find msize or _msize. thanks.
r*******y
发帖数: 1081
11
来自主题: Linux版 - 看看这个 C 代码
I think I get a better one now as I desired
#include
#include
#include
int f(double *a){
return malloc_usable_size(a) - sizeof(void *);
}
int main(void){
double *a= malloc(sizeof(double) * 100);
printf("%d \n", f(a));
}
Thanks.
G**Y
发帖数: 33224
12
来自主题: Linux版 - fscanf is messy
What "%[^\n]\n" means?!
If the first few lines of an input file are:
hello
hello
world
...
the 3rd line is empty, no extra spaces at the end of the lines. What the output should be?
#include
#include
int main(void) {
FILE* fp;
char file[999]="hello.world";
char dummy1[9999], dummy2[9999], dummy3[9999], dummy4[9999];
int line_max=9999;
int i;
if ((fp = fopen(file, "r")) == NULL) {
printf("Cannot open file %s for reading. \n", file);
exit(
g**n
发帖数: 96
13
来自主题: Linux版 - 请教一个编译的问题
// a.cc
int main () {
exit (42);
;
return 0;
}
这几行代码,用gcc编译报错:
error: ‘exit’ was not declared in this scope
原因是源文件没有#include
但是在不改动源文件的条件下,如何能编译成功。试过
gcc -I/usr/include a.cc
没效果。求赐教!
S*A
发帖数: 7142
14
来自主题: Linux版 - 请教一个编译的问题
gcc -include stdlib.h a.cc
d**d
发帖数: 389
15
【 以下文字转载自 Programming 讨论区 】
发信人: dxxd (东邪西毒), 信区: Programming
标 题: 请教一个linux下的POSIX timer的问题。
发信站: BBS 未名空间站 (Fri May 13 17:06:15 2011, 美东)
我用linux下面的POSIX timer, timer_create(),timer_settime(),
为什么在调用了timer_settime()以后,立马就有一个time-out callback? 然后再每过
5秒后有一个time out?
难道不是我调用timer_settime()以后,timer开始计时, 等到5秒以后再出现第一
time out callback 吗?
非常感谢!
代码如下:
#include
#include
#include
#include
#include
void
handle (sigval_t v)
{
tim... 阅读全帖
F****3
发帖数: 1504
16
谢谢各位大哥帮忙!!!!
试了一下autoconf,好像卡住了。
fas133@ubuntu:~/temp/geoip-api-c-master$ autoconf
configure.ac:6: error: possibly undefined macro: AM_INIT_AUTOMAKE
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
./configure终于能执行了。
fas133@ubuntu:~/temp/geoip-api-c-master$ ./configure
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
... 阅读全帖
o******r
发帖数: 259
17
来自主题: Programming版 - [转载] Code效率确实很低!!!(改进版)
【 以下文字转载自 ProtestJapan 讨论区 】
【 原文由 observer 所发表 】
瓶颈在于network
我观察task manager的network usage才1%
估计大部分时间耗在了等待network api返回上
开10个thread, 半天才到count 100
我等到count 200就认为测试通过了
增加thread数目不一定会加快,因为switching
sleep是为了防止在thread之间无用的switch来回
大家试试吧
// Vote.cpp : Defines the entry point for the console application.
//
//#include
#include /* _beginthread, _endthread */
#include
#include
#include
#include "stdafx.h"
#include
#include
l*l
发帖数: 26
18
来自主题: Programming版 - little endian vs big endian
//Please tell me what's the output of the following code for
//bothe little endian and big endian.
#include
#include
int main(void)
{
unsigned long a[2];
unsigned short c;
unsigned char* b;
a[0] = 0x12345678;
a[1] = 0x9abcdef0;
b= (unsigned char*)a;
printf("%02x%02x%02x%02x%02x%02x%02x%02x\n",b[0],b[1],b[2],b[3],
b[4],b[5],b[6],b[7]);
b += 2;
printf("%x\n", *(unsigned int*)b);
b += 4; //b = a+6
printf("
u****u
发帖数: 229
19
来自主题: Programming版 - How to see the content of a library file
1) You sure can. Just search for stdlib.h in your disk, or choose a command
like "open this file" in the right-click menu
2) Most probabily you WON'T be able to see the source code. And , generally
you DON'T want to modify it.

its
r******y
发帖数: 2
20
来自主题: Programming版 - 一个VC++ .net里编译C程序的问题
编译出错: error LNK2019: unresolved external symbol _random referenced in ...
error LNK2019: unresolved external symbol _srandom referenced in ...
我有#include , 为什么还会出这样的错呢?是不是在VC++ .net里编译C程序有
什么要特别设置的呢?我试过VC++ 6.0,碰到同样问题.
谢谢!
r******y
发帖数: 2
21
来自主题: Programming版 - 一个VC++ .net里编译C程序的问题
我选的是unmanaged extensions.不过managed extensions 也不work.
试了main(),可以编译连接成功.但是加上#include 和 random()就不行了.当
然要先改为unmanaged extensions.
Any ideas?
Thanks!
y*******g
发帖数: 33
22
来自主题: Programming版 - an interview question - C programming
Build a software module that belongs to a library that will be used in a
multithreaded embedded environment.
Write the header file that would be included by clients of this library.
Feel free to use any functions from POSIX, stdlib or any C library with
which you are comfortable.
Don’t bother compiling or linking this library though since I’m not
interested in getting the exact syntax just right.
The software module must include
1) One global constant integer, g_nValue0
2) One global co
f********f
发帖数: 8
23
来自主题: Programming版 - 关于C C++ 和java的文件读写问题
要求:a file is to be copied and at the same time its content has to be
reversed (byte by byte)
程序的问题是,当文件很大时, 出错.
请各位大虾,还有聪明的小米,还有好心的xdjms,多多指点. :-)
c语言
#include
#include
#define BUFFER_SIZE 1
int main(int argc, char *argv[])
{
FILE *fp_src, *fp_dest;
void *buffer;
int read;
unsigned int fpSize = 0;
int i,j;
buffer = malloc(BUFFER_SIZE);
if (argc != 3)
{
printf("usage: rcopy srcFile destFile \n");
b*********n
发帖数: 1258
24
想要用qsort来sort一个char array, code如下,但是seg fault
不知道为什么,大家指点一下
#include
#include
#include
char* inString = "ncdoscndisoc";
int compare (const void* a, const void* b)
{
return ((*(char*)a) - (*(char*)b) );
}
int main ()
{
qsort (inString, 12, sizeof(char), compare);
for (int n=0; n<12; n++)
printf ("%c ",inString[n]);
return 0;
}
F*****n
发帖数: 1552
25
来自主题: Programming版 - VC++ 中的 memory leak problem
当年找memory leak的时候颇费了番功夫。后来在msdn里面看到一个方法,很管用,当
时就记下了。给你作个参考,呵呵
//This is how to debug memory leak.
//Add #define _CRTDBG_MAP_ALLOC #include #include
//at the beginning and add the following statement in the program.
//Then run debug (F5)
//System will return where memory leaks, a number within {}
//Then at very beginning of the program, set a breakpoint, run debug.
//When program stops at the breakpoint, in watch window, set the value
//of function _crtBreakAlloc to that num
l*******r
发帖数: 1
26
来自主题: Programming版 - 紧急求助,C语言面试题
下面的modString() 函数是干什么的?
有什么问题?
如何改正?
#include
#include
#include
#include
#include
typedef int int32;
typedef char int8;
void xorStringRounds(int8 *output, int8 *pbDataOne, const int8 *pbDataTwo
, int32 length)
{
int32 i = 0;
for(i=0; i {
output[i] = (int8)(pbDataOne[i] ^ pbDataTwo[i]);
}
return;
}
void itoa( int32 num, int8 *alpha, int32 radix )
{
if( radix == 10 )
{
sprintf(alpha,
g**i
发帖数: 167
27
来自主题: Programming版 - 问个很基础的问题
不好意思,你这个编译的时候怎么总报错啊?
#include
#include
#include
#include
int main()
{
....
return 0;
}
g++编译的时候总报说:
too many arguments to function `int random()'
怎么才能解决这个问题?
谢谢!
t*********n
发帖数: 278
28
来自主题: Programming版 - code question
the sample from programming pearls. But, I got complier error at this line
qsort(a, n, sizeof(char *), pstrcmp). How can I fix this one? Thanx.
#include
#include
#include
int pstrcmp(char **p, char **q)
{ return strcmp(*p, *q); }
#define MAXN 5000000
char c[MAXN], *a[MAXN];
int main()
{ int i, ch, n = 0, maxi, maxlen = -1;
while ((ch = getchar()) != EOF) {
a[n] = &c[n];
c[n++] = ch;
}

c[n] = 0;
qsort(a, n, sizeof(char *), pstrcmp);
}
P********e
发帖数: 2610
29
来自主题: Programming版 - 一道c++的考古题
run this on g++
#include "stdio.h"
#include
int main()
{
int i=2;
if( -10*abs (i-1) == 10*abs(i-1) )
printf ("OMG,-10==10 in linux!\n");
else
printf ("nothing special here\n");
return 0;
}
f******e
发帖数: 164
30
【 以下文字转载自 Linux 讨论区 】
发信人: francise (小飞猫), 信区: Linux
标 题: 奇怪的问题:关于一个简单的malloc()小程序
发信站: BBS 未名空间站 (Sun Mar 30 17:43:48 2008)
我写了一段小程序:
#include
#include
int main(int argc, char *argv[]){
char *buffer;
int num_byte;
num_byte = atoi(argv[1])*1024;
while(1)
{buffer=malloc(num_byte);
free(buffer);
}
}
然后我用
strace ./code 126
结果是:
....
brk(0) = 0x804965c
brk(0x8068e74) = 0x8068e74
brk(0x8069000) = 0x8069000
(Nothing further)
为什么只有有限的几个brk()?
问题是,我的程序明明是无限循环啊
c****n
发帖数: 105
31
来自主题: Programming版 - 这个C++程序为什么不能运行
I just did some test. See the program below:
===============================
#include
#include
#include
int main(int argc, char* argv[])
{
char *a="abcde";
char b[]="abcde";
char* c=(char*)malloc(6);
strcpy(c, a);
printf("%lx, %lx, %lx\n", a, b, c);
printf("%c %c %c\n", a[0], b[0], c[0]);
a[0] = 'f';
printf("%s\n", a);
return 0;
}
==============================
output:
80486d0, bfc74b96, 804b008
a a a
Segmentation fault
char *a="abcde", the compiler generate a str
p**********g
发帖数: 9558
32
来自主题: Programming版 - 一道算法题求教,
#include
#include
int depth[10];
int idx=0;
void display(void)
{
int i;
for(i=0;i printf("%d+", depth[i]);
printf("\n");
}
void sum(int in, int delta)
{
int i;
int op = in;
int step = 1;
if(delta<0) return ;
if(delta==in)
{
depth[idx++] = delta;
display();
depth[--idx] = 0;
}
else
while(1)
{
step = 10*step;
if(op/step)
{
if(
s***e
发帖数: 122
33
我对你对这个Warning/Error的理解有不同看法,我觉得那是因为this在new完成前是不
存在的,不过我同意你说的编译器给加上了static,嗯,我事实上同意了this在static函数里不存在:P
事实上,我用VC6, VS2008, g++ 4.3.1都测试了一下,的确operator new不管是不是
static都可以编译通过,而且连warning都没有。
我猜测可能是C++标准里面就是这么说的吧。
#include
#include
class NewTest
{
public:
NewTest() {}
virtual ~NewTest() {}

public:
void* operator new(size_t size) {
void *ptr = (void *)malloc(size);
printf("my own new\n");
return ptr;
}

void operator delete(void
r*******y
发帖数: 290
34
environment variables?
#include
char * getenv ( const char * name );
int system ( const char * command );
p*******n
发帖数: 273
35
来自主题: Programming版 - 再问一个free()的问题
多谢. 发现free()之后还可以对原来的内存访问,free的作用到底是什么?
#include
#include
char *mkarray()
{
char *a;
a=(char *)malloc(4*sizeof(char));
a[0]='a';a[1]='r';a[2]='e';a[3]='y';
return (a);
}
int main()
{
char *b,*c;
b=mkarray();
c=b+2;
free(b);
printf("%c %c %c %c\n",b[0],b[1],b[2],b[3]);
printf("%c %c \n",c[0],c[1]);
return 0;
}
输出结果是
a r e y
e y
b***y
发帖数: 2799
36
来自主题: Programming版 - [合集] 关于查内存泄露
☆─────────────────────────────────────☆
wealdg (wwwnet) 于 (Sun Feb 3 22:23:04 2008) 提到:
有一巨大的程序如下:
In the main program:
#include "A.h"
#include "B.h"
int main()
{
}
in A.cpp:
#include "C.h"
#include "D.h"
#include "E.h"
Function A1
Function A2
在类B C D E 中仍会调用很多其他的类,在监测内存泄露时,是否只是在主程序(MAIN
)中,加上
#define _CRTDBG_MAP_ALLOC
#include
#include
#include "A.h"
#include "B.h"
//#ifdef _DEBUG
//_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
//#endif
int mai
k**f
发帖数: 372
37
Not sure about Fortran, but in c/c++, you can use the system() function from
.
http://www.cplusplus.com/reference/clibrary/cstdlib/system.html
b***y
发帖数: 2799
38
☆─────────────────────────────────────☆
wmbyhh (wmbyhh) 于 (Sun Jul 6 20:08:03 2008) 提到:
还是以前写的代码,报错stack overflow。
如果去掉里面所有unsigned int为int,define RANGE, N为较小的数如1000,那么编译
就可以正常通过。但是为何不支持unsigned很大的数呢
#include
#include "HeapSort.h"
#include "SelectionSort.h"
#include
#include
#include
#include "MersenneTwister.h"
#define RANGE 1000000 //define the range of input data
#define N 10000000 //define how many random numbers to
generate
m****u
发帖数: 3915
39
来自主题: Programming版 - 问一个C\C++中clock()函数溢出问题
例如这样一个程序:
#include "time.h"
#include "stdio.h"
#include "stdlib.h"
int main(void)
{
clock_t c_start,c_end;
double duration;
c_start = clock();
//My code here ....
c_end = clock();
duration = (double)(c_end - c_start)/CLOCKS_PER_SEC ;
return 0;
}
在32bit机器上,当执行时间过长时(>2000秒), clock()函数会归零重新计时,导致最
后duration为负数,各位大大有什么解决方法不?
(我知道用time()和difftime()可以,但是我现在在一个公用机器上run,用这两个函
数会受其他进程影响,导致结果不准确,有没有用clock(),但是不溢出的方法)
多谢
X****r
发帖数: 3557
40
来自主题: Programming版 - how can I get external program's result in C
#include
#include
int main() {
int fd[2];
pipe(fd);
if (fork()) {
close(1);
dup2(fd[1], 1);
execlp("ssh", "ssh", "serv2", "ls");
} else {
int len;
char buf[256];
while ((len = read(fd[0], buf, 256)) >= 0) {
/* Process piece of output from buf[0] to buf[len-1]. */
}
wait(0);
}
}

ls'.
t****t
发帖数: 6806
41
来自主题: Programming版 - 无法编译一个文件
this is declared in (or ). can't you google it?

成功
g****y
发帖数: 436
42
来自主题: Programming版 - 请教一个C内存泄露问题
【 以下文字转载自 JobHunting 讨论区 】
发信人: ggplay (dfdsf), 信区: JobHunting
标 题: 请教一个C内存泄露问题
发信站: BBS 未名空间站 (Mon Jan 11 10:02:18 2010, 北京)
源代码就是一个2d数组的分配和删除:
编译运行以后发现,程序占用内存按照 4K/单位时间 的速度增加,请问这是怎么回事
呢?
#include
#include
int main()
{
while(1){
int i; /* general purpose variable used for loop index */
int j; /* general purpose variable used for loop index */
int **a; /* this is the array name */
int size_x; /* this variable will be used for the first dimension */
in
e******d
发帖数: 310
43
来自主题: Programming版 - 请教如何使用qsort() to sort string.
I want to sort strings using qsort(), and try the following code, but doesn
't work. Could you please help me out. Thank you.
=============================================
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
int mystrcmp(const void * str1, const void * str2)
{
return strcmp( (const char*)str1, (const char*)str2 ) ;
}
int main()
{
int n = 4;
char *pstr[] = {"God", "Bed", "Act", "Cup"};
qsort(pstr, n, sizeof(char*), mystrcmp);
int i = 0;
for(i = 0;
t****t
发帖数: 6806
44
来自主题: Programming版 - c++ std::abs(int) ambiguous?
abs(int) is declared in stdlib.h (); while fabs(double) and
additional overloaded abs(double) is declared in math.h ().
if you want abs(int), but include only without , then
compiler won't know how to convert int to double/float/long double.
on the other hand, if you want abs(double) but you include only
without , compiler won't know how to convert double to int/long/long
long.
so make sure you included what you need.
g****y
发帖数: 436
45
来自主题: Programming版 - 多线程有什么优化的方法?
heihei, in my test:
gcc: -O1
total loops:2000000000
Time for threaded call:00:00:02
Time for non-threaded call:00:00:03
codes:
#include "threading.h"
#include "timer.h"
#include
#include
#include
int M;
void* cal1(void* vp) {
int flag1 = 0;
for (int n = 0; n < M; n++) {
flag1 = 1;
}
}
void* cal2(void* vp) {
int flag2 = 0;
for (int n = 0; n < M; n++) {
flag2 = 1;
}
}
void* cal0(void* vp) {
int flag2 = 0;
for (int n = 0; n < M; n++) {
fla
M*******r
发帖数: 165
46
来自主题: Programming版 - 借人气问个c++的overflow (转载)
【 以下文字转载自 Quant 讨论区 】
发信人: Morphiner (Ninja Turtle), 信区: Quant
标 题: 借人气问个c++的overflow
发信站: BBS 未名空间站 (Mon Nov 15 12:40:52 2010, 美东)
stack overflow在main后面的{
会是怎么回事?
附上code:
//#include
#include
#include
#include
#include "BarGame.h"
#include
#include
//#include "randomc.h"
//#include "mersenne.cpp" // code for random number generator of
type Mersenne twister
#include "require.h"
//#inclu... 阅读全帖
M*******r
发帖数: 165
47
来自主题: Programming版 - 借人气问个c++的overflow (转载)
Sorry 这里是include的头文件,有一些全局定义在这里面,应该是比main早一步吧
#ifndef BarGame_H
#define BarGame_H
#pragma once
//#include
//#include
//#include
#include
#include
#include
#define MM 8 // size of memory
#define SS 6 // number of strategies per company
#define NN 101 // number of companies
#define PMM 4096 // pow(... 阅读全帖
S******n
发帖数: 489
48
来自主题: Programming版 - 问个关于数组的问题
如下代码,为什么会显示segmentation fault呢。我是用g++编译的。请问这个是为什么
呢?资源不够么?
#include
#include
#define NODE 2000
int main()
{
int graph[NODE + 1][NODE + 1];
int node[NODE + 1];
int nodeCheck[NODE + 1];
for (int i = 1; i <= NODE; i ++)
{
for (int j = 1; j <= NODE; j ++)
{
graph[i][j] = 2;
}
}
return 1;
}
X****r
发帖数: 3557
49
来自主题: Programming版 - tree data conversion
右边第一行应该是1->2,不是1->1吧。
我不懂perl,不过这个程序实在简单,用C写一个也就几行:
int expand(int input[], int output[][2], int start) {
int branch, end = start + 1;
for (branch = 0; branch < input[start]; ++branch) {
output[start][branch] = end;
end = expand(input, output, end);
}
return end;
}
验证程序:
#include
#include
#define MAX 100
int main(int argc, char *argv[]) {
int input[MAX], output[MAX][2] = {0};
int i;
for (i = 1; i < argc; ++i) {
input[i] = atoi(argv[i]);
}
printf... 阅读全帖
首页 上页 1 2 3 4 5 下页 末页 (共5页)