Struct and Pointer Segmentation Error in C

前端 未结 2 551
夕颜
夕颜 2021-01-27 14:32

can anyone help with this segmentation error i keep getting. this code is simple but the error is so hard to figure out.

struct Link {
  int key;
  unsigned dat         


        
2条回答
  •  悲哀的现实
    2021-01-27 14:43

    The part (and everywhere &l is used)

    if (!srt)
        return &l;
    

    is returning the address of a stack variable. Your addInOrder function should probably have the signature

    struct Link* addInOrder(struct Link* srt, struct Link* l);
    

提交回复
热议问题