无法分配struct类型的值

无法分配struct类型的值,c,C,我有一个结构: typedef struct mytime{ float band; float elapsedTime; } timeMs; 为了分配内存: timeMs *bands; bands->band = (timeMs *) malloc(count * sizeof(timeMs)); bands->elapsedTime = (timeMs *) malloc(count * sizeof(timeMs)); 我收到: 无法将“timeMs*”类

我有一个结构:

typedef struct mytime{
    float band;
    float elapsedTime;
} timeMs;
为了分配内存:

timeMs *bands;
bands->band = (timeMs *) malloc(count * sizeof(timeMs));
bands->elapsedTime = (timeMs *) malloc(count * sizeof(timeMs));
我收到:

无法将“timeMs*”类型的值分配给类型为的实体 “浮动”

变量“bands”在设置其值之前使用

此外,内部:

for (unsigned int i = 0; i < count; i++)
{
    bands->band[i] = 0.0;
    bands->elapsedTime[i] = 0.0;
}
--更新---

我发现了最后一个问题。您必须执行以下操作:

bands[i].band += myfunction(..).band
bands[i].elapsedTime += myfunction(..).elapsedTime

您必须为结构分配内存,而不是为单个字段分配内存

timeMs *bands = malloc(count * sizeof *bands);
对于第二个错误,请尝试:

bands[i].band = 0.0;

您必须为结构分配内存,而不是为单个字段分配内存

timeMs *bands = malloc(count * sizeof *bands);
对于第二个错误,请尝试:

bands[i].band = 0.0;

您必须为结构分配内存,而不是为单个字段分配内存

timeMs *bands = malloc(count * sizeof *bands);
对于第二个错误,请尝试:

bands[i].band = 0.0;

您必须为结构分配内存,而不是为单个字段分配内存

timeMs *bands = malloc(count * sizeof *bands);
对于第二个错误,请尝试:

bands[i].band = 0.0;

你能发布你的
timeMs myfunction(…)
的全部代码吗?你在
myfunction
中返回了错误的类型;或者,函数本身是正确的,但您只需要
band
结构元素。@Jongware:我正在返回“mytime”,因此有两个值,band和elapsedtime您可以发布
times myfunction(…)
?您在
myfunction
中返回了错误的类型;或者,函数本身是正确的,但您只需要
band
结构元素。@Jongware:我正在返回“mytime”,因此有两个值,band和elapsedtime您可以发布
times myfunction(…)
?您在
myfunction
中返回了错误的类型;或者,函数本身是正确的,但您只需要
band
结构元素。@Jongware:我正在返回“mytime”,因此有两个值,band和elapsedtime您可以发布
times myfunction(…)
?您在
myfunction
中返回了错误的类型;或者,函数本身是正确的,但您只需要
band
结构元素。@Jongware:我返回“mytime”,因此有两个值,band和elapsedTime@George看起来
myfunction
不返回可以添加到
float
中的内容:myfunction返回“mytime”@George它看起来像
myfunction
不返回可以添加到
float
中的内容:我的函数返回“mytime”。@George它看起来像
myfunction
不返回可以添加到
float
中的内容:我的函数返回“mytime”@George看起来
myfunction
没有返回可以添加到
float
中的内容:myfunction返回“mytime”。