nul terminating a int array

后端 未结 4 1978
青春惊慌失措
青春惊慌失措 2020-12-11 08:16

gcc 4.4.4 c89

I was just experimenting with a int array. And something just came to my mind. Can I nul terminate it. For example, I am using a 0 to nul terminate. Ho

4条回答
  •  离开以前
    2020-12-11 08:31

    Well, you can also change your sentinel from \0 to \\0. And, accordingly, a slight modification in the condition for while loop will get you around your problem.

    while(*p != '\\0')
    

    Now, 0 will not be treated as terminator for the integer array and the whole array gets printed.

提交回复
热议问题