title: Separate basename from the full file path
body: <pre><code>#include &lt;stdio.h&gt;
  int mosrcat(char *o, int tsize, ...) {
    register int cot = 0;
    va_list ap;
    va_start(ap, tsize);
    char *t = va_arg(ap, char *);
    while(t != NULL) {
      while((*(o++) = *(t++)) != 0) {
        cot++;
        if(cot == tsize) {
          *(o) = 0;
          return cot;
        }
      }
      t = va_arg(ap, char *);
      o--;
    }
    va_end(ap);
    return cot;
  }
  
  int mofibasename(const char *file_addr, char *fbasename) {
    register int mo = mosrlen(file_addr) - 1;
    register int n = 1;
    if(*(file_addr+mo) == '/') {
      printf("F\n");
      mo--;
    }
    while(mo != 0) {
      if(*(file_addr+mo) == '/') break;
      mo--;
      n++;
    }
    return mosrcat(fbasename, n, file_addr, NULL);
  }
  
  int main(void) {
    char o[255];
    printf("%d:%s\n", mofibasename("/home/Joe/Skh/", o), o);
    return 0;
  }
  </code></pre>
  
  <p>Here is my code. mofibasename() is to separate the file basename from the full file path.</p>
  
  <p>Ex. <code>/home/Joe/Downloads/x.pdf</code> -> <code>x.pdf</code><br>
  Ex. <code>/etc/passwd</code> -> <code>passwd</code></p>
  
  <p>But the function didn't work. It outputs as <code>/home</code> (Input: <code>/home/Joe/Skh/</code>).</p>
  
  <p>Do I have anywhere wrong? I have tried many time. </p>