Your code fails because
strtok
returns finally
NULL
and you are passing this null pointer to
strstr
. So add an additional check or break your while loop in this case:
while (token) {
token = strtok(NULL, "\n");
if (NULL == token)
break;
if(strstr(token,aa) !=NULL)
{
printf("%s",token);
}
}