我在这里查看此代码:
#include <stdio.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_permutation.h>
int main ( ) {
const long N = 10;
const gsl_rng_type *T = NULL;
gsl_rng *r = NULL;
gsl_permutation *p = NULL;
p = gsl_permutation_alloc ( N );
gsl_permutation *q = NULL;
q = gsl_permutation_alloc ( N );
gsl_rng_env_setup ();
T = gsl_rng_default;
r = gsl_rng_alloc ( T );
printf ( "initial permutation: " );
gsl_permutation_init ( p );
gsl_permutation_fprintf ( stdout, p, " %u" );
printf ( "\n" );
printf (" random permutation:");
gsl_ran_shuffle (r, p->data, N, sizeof(size_t));
gsl_permutation_fprintf (stdout, p, " %u");
printf ("\n");
printf ( "inverse permutation: " );
gsl_permutation_inverse ( q, p );
gsl_permutation_fprintf ( stdout, q, "%u" );
printf ( "\n" );
gsl_permutation_free ( p );
gsl_permutation_free ( q );
return 0;
}
但是,当我尝试编译它时,我得到未处理的异常:访问冲突写入位置错误。我相信,我为所有指针分配了内存,但是错误仍然存在。我对C不太熟悉,所以,任何输入都会受到赞赏。PS当我使用调试器时,它指向这一行:gsl_permutation_fprintf ( stdout, p, " %u" );
谢谢
编辑:我玩过代码并意识到问题可能出在 stdout 语句中。