If either of the C Standard fgets() or fgetws() functions fail, the contents of the array being written is indeterminate. (See undefined behavior 170175.) It is necessary to reset the string to a known value to avoid errors on subsequent string manipulation functions.
...