我有2个结构,我想将一个结构分配给另一个结构,但是当我打印结果时,它打印出废话,函数:“ver_tope”负责执行此操作,我做错了什么?,这里是代码:
#include <stdio.h>
#include <stdlib.h>
#define TAM 4
typedef struct{
char nomyap[40];
int edad;
}t_info;
typedef struct {
t_info pila [TAM];
int tope;
}t_pila;
void ver_tope(const t_pila *p, t_info *d);
int main()
{
t_pila pila;
t_info info;
//I CHARGE BOTH STRUCTS
ver_tope(&pila, &info);
return 0;
}
void ver_tope(const t_pila *p, t_info *d)
{
*d = p->pila[(p->tope)-1];
return ;
}
最佳答案
尝试在 main() ex 中添加 pila.tope 的初始化:
... //I CHARGE BOTH STRUCTS
pila.tope =2;
ver_tope(&pila, &info);
...
这阻止了段错误...
关于c - 我无法在 c 中将一个结构分配给另一个结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32814371/