gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 19:34:38 25 4
gpt4 key购买 nike

我的代码有错误

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) scanf 变量 args 必须作为指针传递。请参阅下面的 scanf 更改。

2) 初始化结构中的变量 - 这就是运行时检查失败 #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));
}

关于c - 运行时检查失败 #3 - T,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43573171/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com