首先定义一个指针 并让它指向字符数组,
字符数组的数组名表示字符串首字符的地址
再定义一个计数器 让其为0
再用while循环 从头开始遍历字符串 遍历一个让计数器加1个
直到遇到 \0 为止!
最后打印出计数器的值!
次计数器的值就是字符串的长度!
#include <iostream>
#include <string.h>
using namespace std;

int main() {

    char str[100] = { 0 };
    cin.getline(str, sizeof(str));

    // write your code here......
    scanf("%s",str);
    char * p=str;
    int count=0;
    while(*p != '\0')
    {
        p++;
        count++;
    }
    printf("%d\n",count);
    return 0;
}```