Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6600811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:40:21+00:00 2026-05-25T18:40:21+00:00

I am trying to capture user input in Go with little luck. I can

  • 0

I am trying to capture user input in Go with little luck. I can get non-spaced words to work:

var s string
println("enter string:")
fmt.Scan(&s)

However, the Go documentation says that scan will delimit at spaces and new lines. So I think I have to set up bufio.Reader’s ReadLine. Here is my attempt, which will not compile:

package main

import (
    "bufio"
    "os"
    "fmt"
)

const delim = '\n'
const file = "file"

func main() {

    r := bufio.NewReader() *Reader

    println("enter string:")
    line, err := r.ReadString(delim)
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
    fmt.Println(line)

}

errors:

1.go:14: not enough arguments in call to bufio.NewReader
1.go:14: undefined: Reader

So, how do I define “Reader”? And if it was defined, would this be the correct way to capture the input as a string, delimited at “\n”, and not at the space? Or should I be doing something completely different?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:40:22+00:00Added an answer on May 25, 2026 at 6:40 pm

    Change

    r := bufio.NewReader() *Reader
    

    to read

    r := bufio.NewReader(os.Stdin)
    

    to fix the problem.

    The original encantation is incorrect because you seem to just copied and pasted the method’s signature from the spec, but the spec defines the signature, not an example of a call, so *Reader in there is the method’s return type (the type your variable r will have). And the method’s sole argument is defined to be rd io.Reader; that interface is conveniently implemented by the os.Stdin symbol which seems like a perfect match for your task.

    P.S.
    Consider reading all the docs in the “Learning Go” documentation section, especially “Effective Go”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get a query string parameter and take an appropriate action in a
I'm working on a web application where I'm trying to capture when the user
we can easily capture a view(screenshot) programmatically in iPhone. But i am trying to
I'm using <canvas> to capture user input in the form of a signature and
In Android, I'm trying to capture user touches as well as User long-touches. I
I am trying to capture when a user presses the del key on a
I'm trying to get this code working within an asp page. when the user
I am trying to capture the day of the month from the user and
I am trying to capture when a user presses Ctrl + C in order
I am trying to let a user capture an image and add it onto

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.