【发布时间】:2016-10-14 18:13:15
【问题描述】:
#include <stdio.h>
#define G 9.81
//结构带来的使用被称为USER_INPUT
typedef struct
{
double weight;
double drag;
double time;
} USER_INPUT;
void getInput(USER_INPUT *); //function prototype - which i think works
void main()
{
USER_INPUT input;
getInput(&input);
//这是输入值应该显示的地方,但它不会返回任何内容
printf("Weight = ", input.weight);
printf("Drag = ", input.drag);
printf("Time =", input.drag);
}
//我从用户那里获取输入的单独函数。它可以工作,但值不会传递回 main
void getInput (USER_INPUT *inpPtr)
{
printf("Please enter the weight:");
scanf("%lf", &inpPtr->weight);
fflush(stdin);
printf("Please enter the drag:");
scanf("%lf", &inpPtr->drag);
fflush(stdin);
printf("Please enter the time:");
scanf("%lf", &inpPtr->time);
fflush(stdin);
return(0); //<- idk if this is right either
}
【问题讨论】:
-
不正确,如果返回类型为
void,则不允许返回值。您的问题是您的printfs 不正确。 ideone.com/f3BqOC
标签: c arrays pointers structure return-value