我是C的初学者.我正在尝试解决一些问题.当我编译代码时,我收到此错误.
[错误]从'void*'无效转换为'triangle*'[-fpermissive]
代码和目的解释如下.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
struct triangle
{
int a;
int b;
int c;
};
typedef struct triangle triangle;
//sort_by_area() function is here
int main()
{
int n;
scanf("%d", &n);
triangle *tr = malloc(n * sizeof(triangle));
for (int i = 0; i < n; i++) {
scanf("%d%d%d", &tr[i].a, &tr[i].b, &tr[i].c);
}
sort_by_area(tr, n);
for (int i = 0; i < n; i++) {
printf("%d %d %d\n", tr[i].a, tr[i].b, tr[i].c);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
正如你所看到我有结构,我试图用输入的数量为它分配内存.并尝试将其用于sort_by_area功能.但问题是 …