pointer arithmetic in C for getting a string

后端 未结 4 1663
暗喜
暗喜 2021-01-26 05:59

I want to get the elements of an array of characters, but no success at all, the problem is that I only get the first and last element and nothing more, my code is:



        
4条回答
  •  耶瑟儿~
    2021-01-26 06:47

    The size of an int can be as big as 4 x the size of a char, so when you do i++ you are actually skipping 3 chars.

    Also, you print out *cad instead of *i.

    To fix change i to char* and print *i instead of *cad

提交回复
热议问题