part of code appended into string, resulting in very strange serial output

Hi, i am getting very strange serial output for my arduino project

the following code

Serial.print("curr[b]entChar:[/b]");Serial.println(currentChar);
printChar(currentChar);

void printchar(char currentChar){
    String charFilename = currentChar + ".tmp";
    Serial.print("charFilename: ");Serial.println(charFilename);
    
    String filepath = customTextPath + charFilename;
    Serial.print("fp:");Serial.println(filepath);
 
     filepath.toCharArray(infile, 20); 
     
     Serial.print("printChar: infile:");Serial.println(infile);
}

results in the following on serial monitor

currentChar:A
charFilename: [b]entChar:[/b]
fp:characters/entChar:
printChar: infile:characters/entChar:

why is part of the code appended into the string???

Sketch uses 36622 bytes (28%) of program storage space. Maximum is 130048 bytes.
Global variables use 2610 bytes (31%) of dynamic memory, leaving 5582 bytes for local variables. Maximum is 8192 bytes.

this the results of uploading on arduino IDE

That's not a program. Please read How to Use the Forum.

-dev:
That's not a program. Please read How to Use the Forum.

perhaps ive used the wrong word.

I am having strange serial output for my arduino project..

tzijie:
perhaps ive used the wrong word.

The word you're looking for is "snippet".

We hate snippets

Please post the complete program. The problem is usually in the part we can't see and in which you are probably not looking.

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.

...R

I think this line is part of your problem:

  String charFilename = currentChar + ".tmp";

Since your printout shows currentChar == 'A' I think you are getting:

  String charFilename = &".tmp"+65;

Since ".tmp" is only 5 bytes long and you are starting at the 66th byte I expect you will get something unexpected.

You can't concatenate a character and a character string. Try this instead:

  String charFilename = currentChar;
charFilename += ".tmp";

I'm not sure that is the only mistake since many of the variable are not declared.

johnwasser:
I think this line is part of your problem:

  String charFilename = currentChar + ".tmp";

Since your printout shows currentChar == 'A' I think you are getting:

  String charFilename = &".tmp"+65;

Since ".tmp" is only 5 bytes long and you are starting at the 66th byte I expect you will get something unexpected.

You can't concatenate a character and a character string. Try this instead:

  String charFilename = currentChar;

charFilename += ".tmp";






I'm not sure that is the only mistake since many of the variable are not declared.

Thank you! i realise strings in arduino and andriod are a little different. and did the concat one at a time. its working now.

String tmpFilename = customTextPath + font;
		tmpFilename += "/";
		tmpFilename += currentChar;
		tmpFilename += ".tmp";
		Serial.print(F("tmpFilename: "));Serial.println(tmpFilename);
		
		tmpFilename.toCharArray(infile, 20); 
		Serial.print("printChar: infile:");Serial.println(infile);