Don't understand strings as parameters
John Abshier
Posts: 1,116
CON _clkmode = xtal1 + pll16x ' use crystal x 16 _xinfreq = 5_000_000 ' 5 MHz cyrstal (sys clock = 80 MHz) LCD_PIN = 0 ' for Parallax 4x20 serial LCD on P0 LCD_BAUD = 19_200 LCD_LINES = 4 VAR byte token[noparse][[/noparse]10] byte head byte tail OBJ lcd : "debug_lcd" PUB main if !lcd.start(LCD_PIN, LCD_BAUD, LCD_LINES) ' start lcd abort lcd.cls head := 0 lcd.cursor(0) ' cursor off lcd.backLight(true) ' backlight on (if available) bytefill(@token,0,10) lcd.str(string("test 2", 13)) GetToken(@teststring,@token) lcd.str(string("returned from GetToken", 13)) lcd.str(@token) pub GetToken(instring, tok) | curChar tail := 0 lcd.str(string("in GetToken", 13)) lcd.putc(instring[noparse][[/noparse]0]) repeat curChar := instring[noparse][[/noparse]head + tail] if curChar == "," quit elseif curChar == "*" quit elseif curChar == $0 quit tok[noparse][[/noparse]tail++] := curChar head := ++tail return DAT ' teststring byte "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47",0 teststring byte "$GPGGA,123519,4807.038,N,01131.000,E,1,08,,,,46.9,M,,*47",0
I am passing the address of teststring and token to GetToken.· But I don't understand how to address them as strings/array of bytes named instring and tok in GetToken.· GetToken never returns and the lcd.putc call writes nothing to the lcd.· I guess I could not use token a an argument to GetToken and use the global variable token, but I really would prefer to use it as an argument so other objects could call it.
Comments
Charlie