2015年11月19日 星期四

[C][Source Code] strlen

Method 1 :
#include <stdio.h>
size_t strlen1(str)
  const char *str;
{
    register const char *s;

    for (s = str; *s != '\0'; ++s)
    {
        printf("a");
    }
    return(s - str);
}

int main()
{
   printf("%d",strlen1("happy"));
}


Method 2 :
#include <stdio.h>
size_t strlen1(str)
  const char *str;
{
    register const char *s;

    for (s = str; *s; ++s)
    {
        printf("a");
    }
    return(s - str);
}

int main()
{
   printf("%d",strlen1("happy"));
}

Reference:

0 意見:

張貼留言