Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
deleted 1 characters in body
Source Link
Linear
  • 22.5k
  • 7
  • 64
  • 73

I'm not sure what's wrong with the block

reader := bufio.NewReader(os.Stdin) fmt.Print("Enter text: ") text, _ := reader.ReadString('\n') fmt.Println(text) 

As it works on my machine. However, for the next block you need a pointer to the variables you're assigning the input to. Try replacing fmt.Scanln(text2) with fmt.Scanln(&text2). Don't use Sscanln, because it parses a string already in memory instead of from stdoutstdin. If you want to do something like what you were trying to do, replace it with fmt.Scanf("%s", &ln)

If this still doesn't work, your culprit might be some weird system settings or a buggy IDE.

I'm not sure what's wrong with the block

reader := bufio.NewReader(os.Stdin) fmt.Print("Enter text: ") text, _ := reader.ReadString('\n') fmt.Println(text) 

As it works on my machine. However, for the next block you need a pointer to the variables you're assigning the input to. Try replacing fmt.Scanln(text2) with fmt.Scanln(&text2). Don't use Sscanln, because it parses a string already in memory instead of from stdout. If you want to do something like what you were trying to do, replace it with fmt.Scanf("%s", &ln)

If this still doesn't work, your culprit might be some weird system settings or a buggy IDE.

I'm not sure what's wrong with the block

reader := bufio.NewReader(os.Stdin) fmt.Print("Enter text: ") text, _ := reader.ReadString('\n') fmt.Println(text) 

As it works on my machine. However, for the next block you need a pointer to the variables you're assigning the input to. Try replacing fmt.Scanln(text2) with fmt.Scanln(&text2). Don't use Sscanln, because it parses a string already in memory instead of from stdin. If you want to do something like what you were trying to do, replace it with fmt.Scanf("%s", &ln)

If this still doesn't work, your culprit might be some weird system settings or a buggy IDE.

Source Link
Linear
  • 22.5k
  • 7
  • 64
  • 73

I'm not sure what's wrong with the block

reader := bufio.NewReader(os.Stdin) fmt.Print("Enter text: ") text, _ := reader.ReadString('\n') fmt.Println(text) 

As it works on my machine. However, for the next block you need a pointer to the variables you're assigning the input to. Try replacing fmt.Scanln(text2) with fmt.Scanln(&text2). Don't use Sscanln, because it parses a string already in memory instead of from stdout. If you want to do something like what you were trying to do, replace it with fmt.Scanf("%s", &ln)

If this still doesn't work, your culprit might be some weird system settings or a buggy IDE.