You should always compile with all warnings enabled (e.g.
-Wall
with
GCC
).
Try
#include<stdio.h>
int xstrlen(const char * a);
int main()
{
char s1[]="bamboo copter";
char s2[]="doraemon";
int l1,l2;
l1 = xstrlen(s1);
l2 = xstrlen(s2);
printf("length of %s is %d\n",s1,l1);
printf("length of %s is %d\n",s2,l2);
return 0;
}
int xstrlen(const char * a)
{
int length =0;
for (length = 0; *a != '\0'; ++a)
{
++length;
}
return length;
}