Extra characters added to end of string in c

后端 未结 3 739
一整个雨季
一整个雨季 2020-12-11 21:41

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 binaryN         


        
3条回答
  •  生来不讨喜
    2020-12-11 22:24

    It should be

    char binaryNumber[17] = "1111000011110000";
    

    This is because strings in C are null terminated. So you will be reading garbage if you don't give an extra character space for the implicit \0 which will be added

提交回复
热议问题