Array length counting anomaly

后端 未结 4 704
挽巷
挽巷 2021-01-26 05:17

The count is returning unpredictable results. Sometimes they are right. Sometimes totally weird. Anyone can tell me what is wrong?

#include 
int l         


        
4条回答
  •  孤独总比滥情好
    2021-01-26 05:49

    You cannot count arrays like that. Only strings are null terminated. If you want that to work reliably, you will need to add an additional element to your array that contains '\0'. But be sure to remember to take into account that your length will no be one larger then the true length because of that '\0'

提交回复
热议问题