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.