computes the length of string str, pointer based - C String

C examples for String:String Function

Description

computes the length of string str, pointer based

int strlen(char *str)
{
  int p;
  for(p = 0; *str != '\0'; str++)
    p++;
  return p;
}

Demo Code

#include <stdio.h>

int strlen(char *str)
{
  int p;//from   ww  w  .  ja v a 2 s  .  c  om
  for(p = 0; *str != '\0'; str++)
    p++;
  return p;
}



int main(void)
{
   char *str = "this is a  test";

   int len = strlen(str);

   printf("%d",len);

   return 0;
}

Result


Related Tutorials