Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 将新数据读入函数内的指针参数?_C_Function_Pointers_Parameters - Fatal编程技术网

C 将新数据读入函数内的指针参数?

C 将新数据读入函数内的指针参数?,c,function,pointers,parameters,C,Function,Pointers,Parameters,我正在创建一个允许用户输入行星数据的程序。在这个函数中,我应该有3个指针参数,因此我可以将函数外部声明的变量的地址传递给指针,然后使用scanf将数据读入这些地址(以指针参数的形式) 程序可以编译,但当我输入新的行星数据时程序崩溃:( temp_x变量已经是指针,因此无需在scanf中使用&运算符,因此您是否尝试在调试器中运行程序? void new_planet_data(double *temp_mass, double *temp_radius, double * temp_dens

我正在创建一个允许用户输入行星数据的程序。在这个函数中,我应该有3个指针参数,因此我可以将函数外部声明的变量的地址传递给指针,然后使用scanf将数据读入这些地址(以指针参数的形式)

程序可以编译,但当我输入新的行星数据时程序崩溃:(


temp_x
变量已经是指针,因此无需在
scanf

中使用
&
运算符,因此您是否尝试在调试器中运行程序?
void new_planet_data(double *temp_mass, double *temp_radius,    double * temp_density)
{


    printf("Enter the planet's mass (earth = 5.9736e24): ");
    scanf("%lf",&temp_mass);

    printf("Enter the planet's radius (earth = 6.37101e6): ");
    scanf("%lf",&temp_radius);

    printf("Enter the air density (earth = 1.2):");
    scanf("%lf",&temp_density);

    planet_mass = *temp_mass;

    planet_radius = *temp_radius;

    planet_density = *temp_density;


}