Hello. I have recently been working with files, and the console outputs strange characters upon compilation. The file also outputs the wrong size of my text file, 32 instead of 30.
The file also outputs the wrong size of my text file, 32 instead of 30.
How are you determining what the "correct" file size is? Right-click your file and check its properties. Windows newlines are often two characters (\r\n).
Your statement that "the console outputs strange characters upon compilation" is meaningless without further elaboration. It would seem you are saying when you compile the file (with what compiler?) from the "console", "strange characters" (like what?) are displayed.
You didn't say how the file was created in the first place. And you didn't say what system you are on. However, someone who says "console" is usually a windows person. So, assuming you created the file with "notepad" and didn't put a newline at the end of the last line, then the file contents you show would contain consist of 32 bytes since the windows newline sequence is character code 13 followed by character code 10 (and you opened the file in binary mode, so these won't be translated to a single '\n').
I assumed he meant "upon running the program", because many IDEs will compile + run automatically. But good catch, because TheDomesticHacker2 should know that proper terminology is important and can help clear confusion.
I didn't even notice at first that the program was printing the buffer, so you must be correct about the missing null terminator in the C-style string causing the "strange characters".