jeudi 11 février 2021

Pointer to char return value is neither NULL neither valid and causes crash?

Hey so Ive spend good 8 hours on this googling everything I could but I still cant figure this out. So ive got this, which passes content of the arrays to function, which searches for the data, and if it finds it, it returns string of numbers(which works perfectly fine) However if it doesnt find anything its meant to return NULL But no matter the ways I try to check for NULL

char *s;
    s = search(arr1[0], arr2[0]);

this never happens

 if(s==NULL) printf("Not found");

yet this crashes the console if NULL was meant to be returned

strlen(s)

Does someone know what is happening here and how to fix it?

Aucun commentaire:

Enregistrer un commentaire