Is this the problem?
if ( Txt == 0 )
TxtLength = strlen( Txt );
You can't get a string length from a null pointer.
Also, you have a memory leak there - Txt needs to be delete[]'ed after you've finished with it.
Rather than try and fix your code, here's an alternative dbEntry that cleans up backspaces, and an example of how it should be used:
char* dbEntry(int Clean)
{
char* Input = dbEntry();
if (Input && Clean)
{
// Step through the input string, with reader & writer pointers.
// For every backspace encountered, we step back 1 for the writer.
// Otherwise, we copy from the reader to the writer and step forward.
// Either way, the reader always steps forward.
char *Writer = Input;
for (char* Reader = Input; *Reader; ++Reader)
{
if (*Reader == 'b')
{
if (Writer > Input)
--Writer;
}
else
{
*Writer = *Reader; // No-op if reader = writer
++Writer;
}
}
*Writer = 0; // Ensure that the string is nul-terminated.
// There was something in the input string, but it's all been erased.
// So clear the input buffer so that it doesn't need to be
// dealt with again.
if (Input[0] == 0)
{
dbClearEntryBuffer();
delete[] Input;
Input = 0;
}
}
return Input;
}
void DarkGDK ( void )
{
// our main loop
while ( LoopGDK ( ) )
{
dbCLS();
char* Input = dbEntry(1);
dbSetCursor(0, 0);
dbPrintC("String entered: ");
dbPrint ((Input ? Input : ""));
delete[] Input; // Delete to avoid memory leak
if (dbReturnKey())
dbClearEntryBuffer();
dbSync();
}
}
Note that the official dbEntry and my alternative are used in exactly the same way - you get a new string each time, and it's up to you to delete[] it.