arrays - println turning up as empty string in go -


so wrote small go program, gives instructions turing machine, , prints selected cells it:

    package main  import "fmt" import s "strings"  func main() {   fmt.println(processturing("> > > + + + . .")); }  func processturing(arguments string) string{     result := ""     dial := 0     cells := make([]int, 30000)     commands := splitstr(arguments, " ")     := 0;i<len(commands);i++ {         switch commands[i] {         case ">":             dial += 1         case "<":             dial -= 1         case "+":             cells[dial] += 1         case "-":             cells[dial] -= 1         case ".":             result += string(cells[dial]) + " "         }     }     return result }  //splits strings delimeter func splitstr(input, delim string) []string{     return s.split(input, delim) } 

problem is, when run, console doesn't display anything. displays nothing. how make work fmt.println resulting string function?

the expression

 string(cells[dial]) 

yields utf-8 representation of integer value cells[dial]. print quoted string output see what's going on:

    fmt.printf("%q\n", processturing("> > > + + + . .")) // prints "\x03 \x03 " 

i think want decimal representation of integer:

 strconv.itoa(cells[dial]) 

playground example.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -