Search code examples
segmentation-faultabstract-syntax-treedirected-acyclic-graphscallocstatic-allocation

Segmentation fault in DAG


How to Fix this Segmentation fault in, I have tried Some alternatives but still it's not working.

strcpy(temp->label,'\0');
strcpy(temp->target,'\0');

Solution

  • this is not correct

    strcpy(temp->label,'\0');
    

    strcpy wants a pointer to a string, you mean

     strcpy(temp->label,"\0");
    

    or even simpler

     strcpy(temp->label,"");
    

    this assumes that temp->lable has memory assigned to it in some way

    EDIT: this is the most efficient way

     temp->label[0] = '\0';