gpt4 book ai didi

c - 如何在 C 中实现具有两个 float 的结构?

转载 作者:行者123 更新时间:2023-11-30 18:17:04 25 4
gpt4 key购买 nike

error: must use "struct" tag to refer to type 'point'

我想要做的就是将坐标存储为结构。这看起来简单得令人发狂,但在访问了 20 个网站并浏览了 Kernaghan 的书后我却做不到。

我错过了什么?

#include <stdio.h>

int main()
{
struct point
{
float x;
float y;
};

point.x = 0.0;
point.y = 1.9;

return 0;
}

最佳答案

您定义了一个名为struct point的类型,而不是使用该定义的变量名称。您想要使用该类型定义结构的实例:

struct point mypoint;  // In C, you could change mypoint to point, but that gets confusing

或者(不太常见)通过将名称放在结构定义之后、分号之前来声明具有(可能是匿名)结构定义类型的变量:

struct {
float x;
float y;
} point;

关于c - 如何在 C 中实现具有两个 float 的结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39215523/

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