在下面的 C 程序中,我们计算给定字符串中的字符数,并在控制台上显示其长度。在执行该程序时,将要求用户输入字符串,然后程序将对字符进行计数并输出字符串的长度。
C 程序 – 在不使用标准库函数strlen的情况下查找字符串的长度
/* C Program to find the length of a String without
* using any standard library function
*/#include<stdio.h>intmain(){/* Here we are taking a char array of size
* 100 which means this array can hold a string
* of 100 chars. You can change this as per requirement
*/char str[100],i;printf("Enter a string: \n");scanf("%s",str);// '\0' represents end of Stringfor(i=0; str[i]!='\0';++i);printf("\nLength of input string: %d",i);return0;}