wat is this function doing

Discussion in 'C' started by cimon, Apr 4, 2007.

  1. cimon

    cimon New Member

    Joined:
    Feb 9, 2007
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    char *img_basename(filename)
    char *filename;
    {
      char *new, *part;
      int len, dex;
    
      len = strlen(filename);  dex = len - 1;
      while (dex > -1) {
        if (filename[dex] == '/') {
          break;
        } else {
          dex--;
        }
      }
      dex++;
      part = &(filename[dex]);
      len = strlen(part);
      new = (char *) malloc ((unsigned) ((len + 1) * sizeof (char)));
      strcpy(new, part);
      return(new);
    }
    
    tis if (filename[dex] == '/') is for filename with spaces??
    and wat wil b copied in new wit tis....... strcpy(new, part);
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    It's getting the part of the filename that is beyond the '/', or the entire name if no '/' is present. Side note: don't waste your time putting "sizeof (char)" in a malloc. Unlike ints or other variables, sizeof char is ALWAYS 1.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice