我想要一個用戶定義的函數,它等價於C中的strlen()函數。在下面的程序中它執行與strlen()相同的函數,但它具有限制它。我怎樣才能讓它計算任何長度的文字。用戶定義的函數,它等價於C中的strlen()C
#include <stdio.h>
#include <conio.h>
void main()
{
int len(char *);
char s[20];
int l;
printf("Enter a string: ");
gets(s);
l=len(s);
printf("length of string is =%d",l);
getch();
}
int len(char *t)
{
int count=0;
while(*t!='\0')
{
count++;
t++;
}
return(count);
}
對我來說這似乎是正確的。你有什麼限制? – Jasper 2012-02-05 01:16:37
你指的是哪一個限制? 「int」count變量的最大值? – Douglas 2012-02-05 01:16:38
當你說它有限制時,你是什麼意思? – sbooth 2012-02-05 01:16:53