String going crazy if I don’t give it a little extra room. Can anyone explain what is happening here?

That’s because you get a not null-terminated string when separator length is forced to 2.

Always remember to allocate an extra character for the null terminator. For a string of length N you need N+1 characters.

Once you violate this requirement any code that expects null-terminated strings (puts() function included) will run into undefined behavior.

Your best bet is to not force any specific length:

char separator[] = "||";

will allocate an array of exactly the right size.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)