[Teensy 2.0++] part of code appended into string, result in strange serial output

Status
Not open for further replies.

tzj

Member
Hi, i am getting very strange serial output from my program..

the following code
Code:
Serial.print("curr[COLOR="#FF0000"]entChar:[/COLOR]");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
Code:
currentChar:A
charFilename: [COLOR="#FF0000"]entChar:[/COLOR]
fp:characters/entChar:
printChar: infile:characters/entChar:

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



Code:
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
 
i realise strings in arduino and andriod are a little different. and did the concat one at a time. its working now.
its prolly the ".tmp" part getting the problem, causing it to read random parts of the code(prolly like how an overflow?)
Code:
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);
 
Status
Not open for further replies.
Back
Top