training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

mystrlen.c (432B)


      1 /* Exercise 8.33 */
      2 
      3 #include <stdio.h>
      4 
      5 size_t strlen(const char *s);
      6 
      7 int main(void)
      8 {
      9    char string[] = "strlen(string): 18";
     10 
     11    printf("strlen(string): %d\n", strlen(string));
     12 
     13    return 0;
     14 } /* E0F main */
     15 
     16 /* computes the lenght of the string s */
     17 size_t strlen(const char *s)
     18 {
     19    int i = 0;
     20 
     21    while( s[i++] != '\0' ) ;
     22 
     23    /* Second version
     24    while( *(s + i++) != '\0' ) ;
     25    */
     26 
     27    return i - 1;
     28 } /* eof strlen() */
     29