1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>

int my_strlen(char* s) {
    printf("s == %p\n", s);
    printf("s == %p  (my_strlen .. enter)\n", s);
    int length = 0;
    while(*s++ != '\0') {}
    printf("s == %p  (my_strlen .. exit)\n", s);
    return length;
}
/*
 *  0000100  H
 *  0000101  i
 *  0000102  '\0'
 *
 *  First time:   s = 0000100
 *  Second time:  s = 0000101
 *  Third  time:  s = 0000102
 *  Returns
 */ 
int main(int argc, char *argv[]) {
    
    char* t = "Hi";
    int len = my_strlen(t);
    printf("t == %p   main .. enter\n", t);
    printf("my_strlen(\"Hi\") == %d\n", len);
    printf("t == %p   main .. exit\n", t);
    
    return 0;
}

This content is protected and may not be shared, uploaded, or distributed.    © 2019 Alexander J. Quinn.