题解 | #获取字符串长度#

获取字符串长度

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;
}

#自学##语言#
全部评论

相关推荐

选钝角的小学生很热爱...:佬,今天收到的嘛?我三面结束二十天了,没人联系😅。请问你base哪里啊
点赞 评论 收藏
分享
阿武同学:基本信息保留前面三行,其他的可以全部删掉,邮箱最重要的你没写,主修课程精简到8个以内,实习里面2/3/4都是水内容的,非要写的话建议两到三句话,项目经历排版优化下,自我评价缩到三行
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务