运行时检查失败#3 - T.

时间:2017-04-23 15:42:26

标签: c

我的代码出错

Run Time Check Failure #3 - T

我多次尝试修复它, 但我失败了。 我添加了指向x,y的指针, 但“运行时检查失败#3 - T” - 同样的错误。 你能帮我修一下这个错误吗?

#include<stdio.h>
#include<math.h>    

typedef struct {
    double x, y;
}location;
double dist(location a,location b)
{
    return sqrt(pow(b.x - a.x, 2.0) + pow(b.y -a.y, 2.0));
}
void func(location l, location e)
{
    double z;
    location a = l;
    location b = e;
    printf("enter two dots:");
    scanf("%lf %lf", a.x, a.y);
    printf("enter two dots:");
    scanf("%1",a, b);
    printf("%.2lf", z);

}

void main()
{
    location l;
    location e;
    func(l, e);
}

1 个答案:

答案 0 :(得分:0)

代码中的问题是:

1)scanf变量args必须作为指针传递。请参阅下面的scanf更改。

2)在struct中初始化变量 - 即运行时检查失败#3警告。请参阅下面的位置初始化。

我也简化了一点。希望有所帮助。

#include<stdio.h>
#include<math.h>    

typedef struct {
    double x, y;
}location;

double dist(location a, location b)
{
    return sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y));
}

void main()
{
    location start = { 0 };
    location end = { 0 };
    printf("Enter start x, y co-ordinates: ");
    scanf("%lf %lf", &start.x, &start.y);

    printf("Enter end x, y co-ordinates: ");
    scanf("%lf %lf", &end.x, &end.y);

    printf("The distance between start and end: %lf\n", dist(start, end));
}