Also it is a bad practice to write while(str[i]!=NULL). When you are on the last character, it will be some valid string character, s[i+1] will be ‘\0’ and s[i+2] will be some random value you cannot predict. It wont affect you in this case but is a bad practice in general especially in the case of something like linked list. The condition while(str[i+2]!=NULL) would have been more appropriate.