printf outputting garbage instead of specific characters

后端 未结 2 1899
清酒与你
清酒与你 2020-12-12 07:47

Well I\'ve weird problem with printf(). It\'s outputting garbage on screen. It\'s kind of connected with memory I guess. Have a look:

char strin         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 08:32

    finish your string2 with null character '\0'

    string2[19] = '\0';
    

    Or you can do it in this way:

    for (i; i < 19; i++) string2[i] = ' ';
    string2[i] = '\0'; // after the end of the loop i= 19 here
    

提交回复
热议问题