

Now you again call i = strcspn (input,keys)Īnd this returns i = 4 because now it finds the first & in position 5. Then you insert the spaces, which works fine, and the string becomes: asdf & asdf&asdf Returns i = 3 since the & is in position 4. The first call to int i = strcspn (input,keys) You're always calling strcspn on the same input, and you're never actually removing the characters that it's finding, so it is always finding the same one.įor example, if your string is asdf&asdf&asdf it takes in 3 arguments: 1st is a string which i insert into, 2nd is a string which i want to insert and 3rd is the index. Yet, when I run my code now, it returns with " *** stack smashing detected ***"Īny Ideas on what this means and how to get around it?ĮDIT Appenda inserts a string into another string at a designated point. So I made a while loop: char keys = "&|" However, my goal is to do that for every special character in the entire input even with multiple special characters (like "asdf&asdf&asdf").

The above code converts input "asdf&asdf" to "asdf & asdf". The following code successfully adds spaces before and after a special character: char keys = "&|" I have a loop running to add spaces between some special characters (&,|,).
