So I am trying to print out a string in C and I am consistently getting extra characters at the end of the string when I print it out. The Code:
char binaryNumber[16] = "1111000011110000";
printf("binary integer: %s\n", binaryNumber);
Output:
binary integer: 1111000011110000▒▒▒▒
can you please help me figure out why this is happening. I think this is the root of some other problems in my code. I had this problem before when I was creating the string in a more complex way, and got extra characters in that case too, but they were different. So I made a string the most basic way possible (method shown here) and am still getting the problem
Let the compiler determine the amount of elements needed
char binaryNumber[] = "1111000011110000";
// same as
// char binaryNumber[17] = "1111000011110000";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With