Taking input in golang

(brian cooper) #1

I am trying to figure out how to use input in go. I created a simple program here in go play ground that shows the code but doesn’t do what it’s supposed to do. It does work in the command line though. The question is what does the “%s” do exactly in line 11? I figured out that it is a string element but what is it’s function? The next part (&hello) is pointing to the var but am not sure how the %s plays a part here.Thanks ahead of time.

(brian cooper) #2

I think I figured it out. when I call fmt.Scanf then it is looking for, in this case, a string and it is pointing that input to the var hello. all this gets called on the last line and prints out the whole thing. Is that correct?

(Johan Dahl) #3

Hi. You definitely figured out it correctly. Why you sending Scanf a pointer to s is so it can set the value of s. If you just sent s it would only receive the value of s in this case the empty string.

(brian cooper) #4

I was trying to figure it out by taking different parts out to see what it would do, but it didn’t give any error messages that helped me figure it out. So it took a while to figure it out. Thanks for the confirmation.

(Curtis Allyn Green) #5

When in doubt, RTM : https://godoc.org/fmt