You might want to declare and initialise files[] first and then use it. That waywe can make sure there was a memory allocation. I guess thats the problem in urcase