当前位置:网站首页>C language: find the length of string

C language: find the length of string

2022-07-04 12:35:00 Nianchi ichthyology programming

problem
Write a function , Find the length of a string , stay main Input string in function , And output its length .
Code

#include <stdio.h>
#include <stdlib.h>
int length(char *s)
{
    
	int i = 0;
	while(*s != '\0'){
    
		i++;
		s++;
	}
	return 1;
}
int main()
{
    
	int len;
	char str[20];
	printf(" Please enter the string :\n");
	scanf("%s",str);
	len = length(str);
	printf(" String has %d Characters .\n",len);
	return 0;
}
原网站

版权声明
本文为[Nianchi ichthyology programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207040951118261.html