wat is this function doing

cimon's Avatar, Join Date: Feb 2007
Go4Expert Member
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);
0
DaWei's Avatar, Join Date: Dec 2006
Team Leader
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.