The line c = txt; introduces a memory leak. It means the original value of c is lost and the memory allocated in main() can never be freed.
When function f() ends, the local array txt[5] is destroyed and c now points to an invalid address. Don't return the address of a local variable.
Use strcpy to copy the characters (not the address) from txt to the block of memory pointed to by c.