【发布时间】:2023-03-30 00:17:01
【问题描述】:
您好已经定义了这个 struct typdef:
typedef struct{
int pid;
int valor;
}hijo;
但是在为其保留内存后,我迭代数组以将值分配给每个结构,但值未正确存储:
hijo *retorno;
retorno=malloc(processes*sizeof(hijo));
while (processes > 0) {
pid = wait(&status);
int valors = WEXITSTATUS(status);
retorno[i].valor=valors;
retorno[i].pid=pid;
--processes; // TODO(pts): Remove pid from the pids array.
}
谢谢。
【问题讨论】:
-
ANSI-C 不是 C 标签所暗示的标准 C。说:你应该离开 1990 年代并使用现代 C。最好的标准 C 是 C11,但至少是 C99。
-
你的意思是值没有正确存储?请发布 MCVE; stackoverflow.com/help/mcve