Advertisement
Patresss

2.2

Sep 2nd, 2014
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. unsigned int strlength_b(const char *s) {
  3.         const char *p=s;
  4.         while (*++s);
  5.         return s-p;
  6.     }
  7. unsigned int strlength_a(const char *s) {
  8.         const char *p=s;
  9.         while (*s++);
  10.         return s-p;
  11.     }
  12. unsigned int strlength_c(const char *s) {
  13.         const char *p=s;
  14.         while (*s) s++;
  15.         return s-p;
  16.     }
  17. int main (void) {
  18.     char str[] = "\na\nd\n\0e\nh\n";
  19.     printf("strlen_a = %u\n",strlength_a(str));//6
  20.     printf("strlen_b = %u\n",strlength_b(str));//5
  21.     printf("strlen_c = %u\n",strlength_c(str));//5
  22.     printf("strlen = %1u\n",strlen(str));//5
  23.     printf("sizeof = %1u\n",sizeof str);//11
  24. return 0;
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement