So, I was working on learning how to use strncpy, and strcpy, which are pretty easy, and when I made some code, and my output had a weird character that wasn't in the program. Here's the trouble code:
The thing with my weird output though, is that I can't copy and paste it. When I
do, it appears as SOHD, with SOH outlined in black. here's a screenshot.
Your screen shot is private, so I can't see it. However, those characters you're referring to are special characters. If you open up your .exe with the same file editor, you'll notice similar characters.
Everything seems fine there otherwise. Is myText a character array? Why do you need thirdText to be Months + 1 large? Your issue is probably that + 1, or the program is reading the character array further into memory than it needs to go and is returning funky characters. You should really set your thirdText[Months] to '\0' so that doesn't happen, and that you're displaying some random characters.
If you could post your entire code, or make that screenshot public, I could possibly help you further.
oops. sorry. Can you see it now? Yes, myText is a character array. And you're right, I don't need thirdText to be that big. I changed it back and compiled, yet it still pops up with the same character. I also did char thirdText[Months] = "\0";
but that character is still there. Here's some other code that might be helpful.
1 2 3 4 5
//My includes
#include <iostream>
#include <cstring>
#include <string>
1 2 3 4
//Month enum
//EDIT: I changed monthNames so there were no assigned values
//but that didn't work either.
enum monthNames {January, February, March , April, May, June, July, August, September, October, November, December, Months};
strncpy() doesn't append a NULL character automatically to the end of destination if ever the source is longer than the limit. printing destination so will cause weird output since there is no null terminator to signal the end of the string, The insertion operator will just print every byte starting from &thirdText[ 0 ] up to whenever it found a null terminator. (the memory following &thridText[ Months ] could be some random data)
therefore, you should append NULL manually if ever source length is greater than the limit (3rd argument)