题解 | #获取字符串长度#
获取字符串长度
https://www.nowcoder.com/practice/9a2d212d23f5436c80607d5e68c6d12a
#include <stdio.h>
#include <string.h>
int main()
{
char str[50]; //图省事没用malloc
int len;
int i;
fgets(str, 50, stdin); //gets不安全,用fgets代替
while (str[i] != '\n') //fgets会录入最后的回车
i++; // 这一段删除回车
str[i] = '\0';
len = strlen(str);
printf("%d", len);
return 0;
}
#自学##语言#
查看6道真题和解析
