Showing year as three digits!

You defined test to be 20 characters long. Sprintf() puts a null character at the end, which takes up a character. Test needs to be bigger.

I'm not sure I understand what you are doing with the variable "chars". sprintf returns the number of characters written. "chars" isn't an int, it is an array of characters, why?