fmt.Scanf not working properly in Go -
i'm trying out snippet supposed test out fmt.scanf, doesn't seem work expected:
package main import ( "fmt" "time" ) func main() { fmt.println("what favorite color?") var favoritecolor string fmt.scanf("%s", &favoritecolor) fmt.println("fave color is", favoritecolor) fmt.println("what favorite food?") var myfood string fmt.scanf("%s", &myfood) fmt.printf("i %s too!\n", myfood) fmt.printf("wait 2 seconds please...\n") time.sleep(2000 * time.millisecond) fmt.printf("your favorite color %s, , nutrient best %q\n", favoritecolor, myfood) }
however first reply taken, programme continues end , returns:
what favorite color? reddish fave color reddish favorite food? too! wait 2 seconds please... favorite color red, , nutrient best ""
why sec scanf function beingness ignored? makes no sense me.
i installed go using recent 64bit bundle on windows 7.
put \n
after %s
consumes newline type. otherwise newline goes next scan.
go scanf
No comments:
Post a Comment