Strange output...

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
SonOfBc
Posts: 8
Joined: Mon Nov 12, 2012 10:39 pm

Strange output...

Post by SonOfBc » Mon Nov 26, 2012 10:36 pm

Would anyone like to run this simple code and see if you get the same strange output as I do?

Code: Select all

Device = 18F4525
Clock = 20

#option LCD_DATA = PORTD.0
#option LCD_RS = PORTD.7
#option LCD_EN = PORTD.6

Include "LCD.bas"


Structure  TestStructure
    
    DowStr As String(3)
    MthStr As String(3)
    
End Structure 

Public Dim Test As TestStructure

Const    
    WeekArray(7) As String = ("Thu","Fri","Sat","Sun","Mon","Tue","Wed"),
    MonthArray(12) As String = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
    
    


Test.DowStr = WeekArray(1)
Test.MthStr = MonthArray(2)


LCD.Cls
LCD.WriteAt(1,1,Test.DowStr)  'Test.DowStr should = "Fri" but it is = to "FriMar" ????
LCD.WriteAt(2,1,Test.MthStr)  'Test.MthStr does = the expected "Mar"
When I print this to my LCD I get the strange result as noted in the comments in the code. Same thing happens when it prints to a text file on my SD card.

Anyone??

Thanks
SamB

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Mon Nov 26, 2012 11:32 pm

A string requires a null terminator, so your strings should be dimensioned as 4 characters, not 3 as your code shows...

SonOfBc
Posts: 8
Joined: Mon Nov 12, 2012 10:39 pm

Thanks...

Post by SonOfBc » Tue Nov 27, 2012 4:13 am

David Barker wrote:A string requires a null terminator, so your strings should be dimensioned as 4 characters, not 3 as your code shows...
Thought I had little gremlins in my code... :)

Post Reply