C 如何修复';预期标识符或';结构返回函数中的(';before';int';';错误

C 如何修复';预期标识符或';结构返回函数中的(';before';int';';错误,c,C,我创建的C代码输出直径,面积,周长从一个单一的功能。 我正在使用结构输出数据。但是,在创建输出结构的函数时,我得到以下错误:“预期标识符或”(“int”之前的“) 我试过做代码中所说的显而易见的事情,但没有效果 #include <stdio.h> struct circle { int diameter; int area; int circumference; }; typedef struct circle one; struct prope

我创建的C代码输出直径,面积,周长从一个单一的功能。 我正在使用结构输出数据。但是,在创建输出结构的函数时,我得到以下错误:“预期标识符或”(“int”之前的“)

我试过做代码中所说的显而易见的事情,但没有效果

#include <stdio.h>

struct circle
{
    int diameter;
    int area;
    int circumference;
};
    typedef struct circle one;

struct properties (int r)
{
    struct circle.one.diameter = 2 * r;
    struct circle.one.area = (22 * r * r) / 7;
    struct circle.one.circumference = (2 * 22 * r) / 7;

    return (one);
}

int main ()
{
    int a;
    int result;
    printf ("text");
    scanf ("%d", &a);
    result = properties (a);
    printf ("%d%d%d", result );

    return 0;
}
#包括
结构圆
{
内径;
内部区域;
整数周长;
};
typedef结构圈一;
结构属性(intr)
{
结构圆直径=2*r;
结构圆.one.area=(22*r*r)/7;
结构圆1周长=(2*22*r)/7;
返回(一);
}
int main()
{
INTA;
int结果;
printf(“文本”);
scanf(“%d”和“&a”);
结果=属性(a);
printf(“%d%d%d”,结果);
返回0;
}

我希望输出的是直径、面积和周长的值。

这是一个工作程序,纠正了许多错误。请注意,它正在进行整数除法,因此结果将向下舍入到最接近的整数

#include <stdio.h>

struct circle
{
    int diameter;
    int area;
    int circumference;
};

typedef struct circle one;

one properties (int r)                          // use the typedef
{
    one calcs;                                  // define a struct
    calcs.diameter = 2 * r;                     // clean up the act
    calcs.area = (22 * r * r) / 7;
    calcs.circumference = (2 * 22 * r) / 7;

    return calcs;
}

int main (void)                                 // full definition
{
    int a;
    one result;                                 // this should be a struct
    printf ("radius: ");                        // sensible prompt
    scanf ("%d", &a);
    result = properties (a);
    // space separate the output, pass each value
    printf ("%d %d %d", result.diameter, result.area, result.circumference);
    return 0;
}
#包括
结构圆
{
内径;
内部区域;
整数周长;
};
typedef结构圈一;
一个属性(intr)//使用typedef
{
one calcs;//定义一个结构
calcs.diameter=2*r;//清理行动
计算面积=(22*r*r)/7;
计算周长=(2*22*r)/7;
返回计算;
}
int main(void)//完整定义
{
INTA;
一个结果;//这应该是一个结构
printf(“半径:”;//提示
scanf(“%d”和“&a”);
结果=属性(a);
//空格分隔输出,传递每个值
printf(“%d%d%d”,结果.直径,结果.面积,结果.周长);
返回0;
}
程序输出

radius: 3 6 28 18 半径:3 6 28 18
struct properties(int r)
不编译。它既不是一个
struct
也不是一个函数定义。您的函数缺少返回类型;根据main中的代码,它应该返回一个int。
printf(“%d%d%d”,result);
缺少两个参数,但这是您在这里遇到的最小问题。
struct circle.one.=
应该做什么也不清楚。也许您需要重新阅读有关使用C structs的教程。@Bathsheba 3尝试355/113而不是22/7;这对在浮点运算中使用6个有效数字很好。