0

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');
vimuth
  • 5,064
  • 33
  • 79
  • 116
  • struct Listnode { char data[50]; int leader,block,u_goto,c_goto; struct Listnode *next; char label[10],target[10]; }*temp,*cur,*first=NULL,*last=NULL,*cur1; – VIRTUAL_MEMORY Jan 28 '23 at 17:42

1 Answers1

0

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';
pm100
  • 48,078
  • 23
  • 82
  • 145