题解 | #获取字符串长度#
获取字符串长度
https://www.nowcoder.com/practice/9a2d212d23f5436c80607d5e68c6d12a
#include <iostream>
using namespace std;
#include<stdio.h>
int main() {
char arr[100] = {0};
char* str = arr;
scanf("%[^\n]s",str);//因为scanf取一行字符时碰到空格,制表符,\r,\n就结束了。所以用%[^\n],这个格式符的意思是读\n之外的所有字符,也就是说读到/n为止!
int count=0;
while((*str)!='\0')
{
count++;
str++;
}
printf("%d",count);
return 0;
}
