How to return the size and name of largest file in a directory hierachy.... Return a structure... struct sizedFile { unsigned int length ; char pathName[8000] ; } it works.... but involves copying a lot of data... What about return a pointer to the structure! struct sizedFile *biggestFile(....) { struct sizeFile biggestFileRet ; ... ... return &biggestFileRet ; } But returning a pointer to data on the stack which will be reused! a CSCI 335 topic and Java-like solution struct sizedFile *biggestFile(....) { struct sizeFile *biggestFilePtr = (struct sizeFile *)malloc(sizeof(struct sizeFile) ; .... return biggestFilePtr ; } But most of these returns will *not* be used! Lots of inaccessable memory. The solution -- You only need to keep up with the largest file! Use free(...), but be careful! This is for CSCI 335. **** Java and Python use garbage collection to avoid this problem. Let's take the low path. Have the caller allocate the buffer! A bit like file I/O in C! unsigned int biggestFile(...., char *biggestPathName) { struct sizeFile forTheChild ; .... .... calls size = biggestFile(forTheChild) ; ... get the size and fill in the name } No malloc() [dynamic memory]. All data on the stack is in use. One problem: How do we indicate the directory contains no file? Check the return value? Is it zero? Nope, the largest file may be of size 0. Use -1 as flag? Nope, -1 in not an unsigned int. Set pathName to start with '\0'? That should work if (forTheChild[0]) { size = biggestFile(forTheChild) ; if (size>biggestSoFarSize) .... }