Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   wat is this function doing (http://www.go4expert.com/forums/wat-function-doing-t3754/)

cimon 5Apr2007 04:01

wat is this function doing
 
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);

DaWei 5Apr2007 05:41

Re: wat is this function doing
 
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.


All times are GMT +5.5. The time now is 04:27.