Computing a String's Length
int length(char s[])
{
int cnt;
for(cnt = 0; s[cnt] != '\0'; ++cnt)
;
return cnt;
}
#include <stdio.h>
main()
{
printf("\"otter\"\t%d\n",
length("otter"));
printf("\"\"\t%d\n", length(""));
printf("\"a\"\t%d\n", length("a"));
}
The outputs are:
"otter" 5
"" 0
"a" 1
This is program
pg265.c
Previous slide
Next slide
Back to first slide
View graphic version