I want to write a function, that deletes an entry of a structure list if it finds a substring in the name of the author saved in the structure. The problem is, that strstr() does not seem to find any match. I dont want to know if I am deleting the entries right or moving the list pointers in the right way (wanna figure that out myself).
void z(LIBRARY *first){
int i = 0, j = 0 ;
LIBRARY *nextZ = first->next , *prevZ = first;
char *name = (char*) malloc (102*sizeof(char)), *name2 = (char*) malloc (102*sizeof(char)), c ;
getchar();
fgets(name, 102, stdin); // Function gets the string the user is looking for.
while (name[j]!= '\0'){
name[j]= toupper(name[j]); // Converts it to upper case to ignore case types.
j++;
}
j=0;
printf("%s", name);
while ( nextZ ){ // Function starts going through the list of structures
name2 = nextZ->authors; //Function gets string saved in current structure->authors
while (name2[j]!= '\0'){
name2[j]= toupper(name2[j]);
j++;
}
j = 0;
printf("%s", name2);
if ( (strstr( name2, name))!=NULL ){
/*This is where the problem is. It seems like
the function never finds a substring in the structure->authors entry.*/
i++;
prevZ->next = nextZ->next;
nextZ = nextZ->next->next;
}
else {
prevZ = prevZ->next;
nextZ = nextZ->next;
}
}
printf("Vymazalo sa %d zaznamov\n", i); //Prints out how many entries of the list got deleted.
}