题解 | 获取字符串长度

获取字符串长度

https://www.nowcoder.com/practice/9a2d212d23f5436c80607d5e68c6d12a

#include <stdio.h>

int main() {

    char str[100] = { 0 };
    gets(str);

    // write your code here......
    int i,count=0;
    for(i=0;i<100;i++)
    {
      if(str[i]!='\0')
      {
        count++;
      }
    }
    printf("%d", count);
    return 0;
}

基础版:首先题目说统计字符串的个数,想到了用for循环去遍历字符串中的内容,判断的边界为'\0'。所以需要定义两个变量,是i用于for循环,一个是count用于记录个数。

#牛客创作赏金赛##秋招笔面试记录#
全部评论

相关推荐

牛客21331815...:像我一投就pass,根本不用焦虑泡池子
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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