Find the size of a string pointed by a pointer

前端 未结 9 1056
一整个雨季
一整个雨季 2020-12-08 20:39
#include 

int main ()
{
    char *ptr = \"stackoverflow\"

}

Is there any way to find the length of stackoverflow pointed by ptr, a

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 21:09

    #include
    main()
    {
        int mystrlen(char *);
        char str[100];
        char *p;
        p=str;
        printf("Enter the string..?\n");
        scanf("%s",p);
        int x=mystrlen(p);
        printf("Length of string is=%d\n",x);
    
    
    }
    int mystrlen(char *p)
    {
        int c=0;
        while(*p!='\0')
        {
            c++;
            *p++;
        }
        return(c);
    }
    

    simple code to understand

提交回复
热议问题