You assumed that you did know how much memory by doing this:
So how big were you expecting the filename string to be in the code above? Whatever that is, you need to create or have access to a buffer of that size first before this code is invoked.Code:for (i=lastslash;i<=strlen(pat);i++)
filename[i-lastslash]=pat[i];
Once you know that, then you use new[] and delete[] to allocate and deallocate memory. But as JohnW pointed out, it would be much worth your while to write a string class and use that instead. But that requires you know how to use dynamic allocation (new[]/delete[]).
Regards,
Paul McKenzie

