Why is this code giving segmentation fault after printf("9\n")
. Basically the code crashes as soon as the while loop starts. Can anyone tell me how to fix it? Consider I called the headrvLoader()in
main()```
tetypedef struct cartbook{ int issue; char *id; struct cartbook *next;}cartstruct;struct cartbook *headrv;void headrvLoader(){ FILE *fp1,*fp2;printf("1\n"); struct cartbook *current,*prev,*p;printf("2\n"); fp1=fopen("ReservedBooks.txt","r");printf("3\n"); fp2=fopen("ReservedUserId.txt","r");printf("4\n"); headrv=(struct cartbook*)malloc(sizeof(struct cartbook));printf("5\n"); char *str;printf("6\n"); current=(struct cartbook*)malloc(sizeof(struct cartbook));printf("7\n"); headrv->next=current;printf("8\n"); prev=headrv;printf("9\n"); while(true) { if(fgets(current->id,50,fp2)==NULL) { printf("jhhj"); current=NULL; prev->next=NULL; }}}