Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- unsigned int strlength_b(const char *s) {
- const char *p=s;
- while (*++s);
- return s-p;
- }
- unsigned int strlength_a(const char *s) {
- const char *p=s;
- while (*s++);
- return s-p;
- }
- unsigned int strlength_c(const char *s) {
- const char *p=s;
- while (*s) s++;
- return s-p;
- }
- int main (void) {
- char str[] = "\na\nd\n\0e\nh\n";
- printf("strlen_a = %u\n",strlength_a(str));//6
- printf("strlen_b = %u\n",strlength_b(str));//5
- printf("strlen_c = %u\n",strlength_c(str));//5
- printf("strlen = %1u\n",strlen(str));//5
- printf("sizeof = %1u\n",sizeof str);//11
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement