使用功能我写了这个代码,但它给了长0。I上午初学者,也找不到什么是错的这这是我的代码:查找字符串长度,而不使用strlen的和用C
#include <stdio.h>
#include <conio.h>
int strlgnth(char *s); /* func prototype */
int strlgnth(char *s)
{
int i;
{
for (i = 0; s[i] != '\0'; i++);
i = i++;
}
return i;
}
int main()
{
char s[1000], i, n;
printf("Enter a string: ");
scanf("%s", s);
{
i = strlgnth(s);
}
printf("Length of string: %d", n);
getch();
return 0;
}
请妥善格式化你的代码。 –
你有几个不必要的方括号,为什么? – Nabla
为什么没有循环体的'for'语句? –