pointer arithmetic in C for getting a string

后端 未结 4 1677
暗喜
暗喜 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:44

    Other answers have told you why it plain doesn't work, I'm wonder why you're not just iterating until the null terminator?

    void getcharacters(char *cad)
    {
     char *i;
     for (i = cad; *i; i++) {
         printf("%c\n",*i);
     }
    }
    

提交回复
热议问题