I have simple go program that converts miles to kilometers:
const kmInMile = 1.609344
func main() {
var miles float64
fmt.Print("Enter miles: ")
fmt.Scanf("%f", &miles)
fmt.Println(miles)
km := kmInMile * miles
fmt.Println(miles, "miles =", km, "km")
}
If I pass "lls" as input to scanf:
Enter miles: lls
Output is:
0
0 miles = 0 km
alexandrkrivosheev$ ls
hello main.go
so the first char of input was taken and all other were executed as command. Why does it happened and how can i prevent this?
Full terminal session:
alexandrkrivosheev$ ./hello
Enter miles: lls
0
0 miles = 0 km
alexandrkrivosheev$ ls
hello main.go
alexandrkrivosheev$