c - 我无法在 c 中将一个结构分配给另一个结构

标签 c struct

我有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/

相关文章:

c - 从二叉树搜索中删除节点

c - 进程 Hook 问题

c++ - "Reading"POD 预增量结果不会产生未定义的行为。为什么呢?

arrays - 删除所有具有特定索引的字段

c - 指向结构的指针

c++ - 错误 : expected primary-expression before ')' token (C)

c - fscanf 没有将数据保存到结构中?

c - c - 套接字编程中的发送和接收结构

c - Lex - 将运算符识别为标记

c、创建 child 和wait()