{"id":736,"date":"2026-10-04T11:00:00","date_gmt":"2026-10-04T05:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-user-input-programs\/"},"modified":"2026-11-29T01:29:43","modified_gmt":"2026-11-28T19:59:43","slug":"go-user-input-programs","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-user-input-programs\/","title":{"rendered":"Go User Input Programs: fmt.Scan, bufio and os.Args"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go user input programs let your code ask a question and use the answer, which is the moment a program starts to feel alive. In this post, you will read words, numbers and full lines from the keyboard, and you will also read values from the command line. Every program comes with sample input and its exact output, followed by the input questions interviewers ask most.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before you start, finish our <a href=\"https:\/\/smitabharat.com\/blog\/go-hello-world-print-programs\/\">Go print programs with output<\/a>, because every input program also prints. You should also know <a href=\"https:\/\/smitabharat.com\/blog\/how-to-run-a-go-program\/\">how to run a Go program<\/a> from a terminal. We tested every program on Go 1.27.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is Go User Input?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">User input is any data your program receives while it runs. It can come from the keyboard, from command line arguments or from another program through a pipe. In Go, the keyboard input arrives on standard input, which the <code>os<\/code> package calls <code>os.Stdin<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of standard input as a letterbox. The user drops text into it, and your program picks the text up when it is ready. Different tools pick it up in different ways, one word at a time or one full line at a time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Go User Input Matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Almost every useful tool needs Go user input of some kind. For example, a calculator needs numbers, a quiz needs answers and a login screen needs a name. Coding rounds also give their test data on standard input, so you must read it quickly and correctly.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Coding tests:<\/strong> sites like HackerRank and LeetCode style judges send input on stdin.<\/li>\n\n\n<li><strong>Command line tools:<\/strong> tools read flags such as <code>-port=8080<\/code> when they start.<\/li>\n\n\n<li><strong>Scripts:<\/strong> one program can pipe its output into another Go program.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How Go User Input Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Your program can read Go user input in three main ways. The diagram shows where each one gets its data.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-diagram-1-1024x640.png\" alt=\"Go user input diagram showing keyboard, command line arguments and pipes flowing into a Go program\" class=\"wp-image-732\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Keyboard text and pipes arrive on os.Stdin, while command line arguments arrive in os.Args before the program starts.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The table below shows which tool to pick for each job.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Tool<\/th><th>Reads<\/th><th>Best for<\/th><\/tr><\/thead><tbody><tr><td>fmt.Scan<\/td><td>Words separated by spaces or new lines<\/td><td>Quick numbers and single words<\/td><\/tr><tr><td>fmt.Scanln<\/td><td>Words on one line only<\/td><td>One line of values<\/td><\/tr><tr><td>fmt.Scanf<\/td><td>Values in a fixed format<\/td><td>Input like 10-20<\/td><\/tr><tr><td>bufio.Reader<\/td><td>One full line with spaces<\/td><td>Names and sentences<\/td><\/tr><tr><td>bufio.Scanner<\/td><td>Many lines in a loop<\/td><td>Files and big test input<\/td><\/tr><tr><td>os.Args<\/td><td>Words after the program name<\/td><td>Simple command line tools<\/td><\/tr><tr><td>flag<\/td><td>Named options like -name<\/td><td>Real command line tools<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In each example below, we first show the input you type. Then we show the output. In a real terminal, you will also see your typed text after each prompt.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go User Input with fmt.Scan<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>fmt.Scan<\/code> is the simplest way to read Go user input. It reads words separated by spaces or new lines and stores them in the variables you pass. You must pass a pointer, written with <code>&amp;<\/code>, so <code>Scan<\/code> can change your variable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 1: Read Your Name<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This program asks for a name and greets the user.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ main asks for a name and says hello\nfunc main() {\n    var name string \/\/ an empty text variable to hold the answer\n\n    fmt.Print(\"Enter your name: \") \/\/ Print keeps the cursor on the same line\n    fmt.Scan(&amp;name)                \/\/ &amp; gives Scan the address of name, so it can fill it\n    fmt.Println(\"Hello,\", name+\"!\") \/\/ + joins the name and the \"!\"\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Asha<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter your name: Hello, Asha!<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>&amp;name<\/code> passes the address of <code>name<\/code>, so <code>Scan<\/code> can fill it. We used <code>Print<\/code> for the prompt, so the cursor stays on the same line.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 2: Add Two Numbers<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Scan<\/code> can fill many variables in one call. It also converts the text to the right type for you.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ main reads two whole numbers and prints their sum\nfunc main() {\n    var first, second int \/\/ two int variables, both start at 0\n\n    fmt.Print(\"Enter two numbers: \")\n    fmt.Scan(&amp;first, &amp;second) \/\/ Scan fills them in order and turns the text into ints\n\n    fmt.Println(\"Sum:\", first+second)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>12 30<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter two numbers: Sum: 42<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The user can type both numbers on one line or on two lines. <code>Scan<\/code> treats spaces and new lines the same way.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 3: Answer a Yes or No Question<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Go user input becomes useful when your program makes a choice with it. This program reads one word and answers in two different ways.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ main asks a question and replies based on the answer\nfunc main() {\n    var answer string\n\n    fmt.Print(\"Do you like Go? (yes\/no): \")\n    fmt.Scan(&amp;answer)\n\n    \/\/ == checks if two strings are exactly the same\n    if answer == \"yes\" {\n        fmt.Println(\"Great! Let's write more Go.\")\n    } else {\n        fmt.Println(\"Give it a week. It grows on you.\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>yes<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Do you like Go? (yes\/no): Great! Let's write more Go.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First, <code>Scan<\/code> stores the typed word in <code>answer<\/code>. Then the <code>if<\/code> compares it with &#8220;yes&#8221;. If they match, the first message prints, and any other word prints the second one.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 4: Check for Bad Input<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">What if the user types letters instead of a number? <code>Scan<\/code> returns an error, and you should always check it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ main reads an age and stops kindly if the input is not a number\nfunc main() {\n    var age int\n    fmt.Print(\"Enter your age: \")\n\n    \/\/ Scan returns two values: how many items it read, and err (the error value)\n    \/\/ _ means we do not need the first value\n    _, err := fmt.Scan(&amp;age)\n\n    \/\/ nil means \"no error\", so != nil means something went wrong\n    if err != nil {\n        fmt.Println(\"Invalid input:\", err)\n        return \/\/ stop main here\n    }\n    fmt.Println(\"Next year you will be\", age+1)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>abc<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter your age: Invalid input: expected integer<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Scan<\/code> returns two values: how many items it read and an error. Here the error says it expected an integer, so the program stops kindly instead of using a wrong value.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Read a Full Line of Go User Input<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>fmt.Scan<\/code> stops at the first space. So for a full name like &#8220;Asha Mehta&#8221;, you need a line reader from the <code>bufio<\/code> package.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 5: Read a Full Name with bufio.Reader<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>bufio.NewReader<\/code> wraps standard input. Its <code>ReadString<\/code> method reads until it finds the character you give it, here the new line.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"bufio\"   \/\/ bufio reads input in bigger pieces, such as full lines\n    \"fmt\"\n    \"os\"      \/\/ os.Stdin is the keyboard input\n    \"strings\" \/\/ helpers for working with text\n)\n\n\/\/ main reads a full name and counts its letters without the spaces\nfunc main() {\n    reader := bufio.NewReader(os.Stdin)\n    fmt.Print(\"Enter your full name: \")\n\n    \/\/ Step 1: read everything up to and including the new line\n    line, _ := reader.ReadString('\\n')\n\n    \/\/ Step 2: remove the new line and any extra spaces at the ends\n    name := strings.TrimSpace(line)\n\n    \/\/ Step 3: drop the spaces inside the name, then count what is left\n    letters := strings.ReplaceAll(name, \" \", \"\")\n    fmt.Printf(\"Welcome, %s! Your name has %d letters.\\n\", name, len(letters))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Asha Mehta<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter your full name: Welcome, Asha Mehta! Your name has 9 letters.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>ReadString<\/code> keeps the new line at the end, so we remove it with <code>strings.TrimSpace<\/code>. This also removes the <code>\\r<\/code> that Windows adds, which avoids a very common bug.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 6: Read Many Lines with bufio.Scanner<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>bufio.Scanner<\/code> reads one line per loop. It stops when the input ends, which is how judges send test data.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"bufio\"\n    \"fmt\"\n    \"os\"\n)\n\n\/\/ main prints every input line with its line number\nfunc main() {\n    scanner := bufio.NewScanner(os.Stdin)\n    count := 0\n\n    \/\/ scanner.Scan() reads the next line and returns false when input ends\n    for scanner.Scan() {\n        count++\n        fmt.Printf(\"Line %d: %s\\n\", count, scanner.Text()) \/\/ Text() gives the line without the new line\n    }\n    fmt.Println(\"Total lines:\", count)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>apple\nbanana\ncherry<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Line 1: apple\nLine 2: banana\nLine 3: cherry\nTotal lines: 3<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>scanner.Scan()<\/code> returns false at the end of input, so the loop stops by itself. <code>scanner.Text()<\/code> gives the line without the new line character.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 7: Count the Words in a Sentence<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here is an everyday use of a full line of Go user input. The program reads a sentence and tells you how many words it has.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"bufio\"\n    \"fmt\"\n    \"os\"\n    \"strings\"\n)\n\n\/\/ main reads one sentence and counts its words\nfunc main() {\n    reader := bufio.NewReader(os.Stdin)\n    fmt.Print(\"Type a sentence: \")\n    line, _ := reader.ReadString('\\n')\n\n    \/\/ Fields splits the text at spaces and gives back a slice (list) of words\n    words := strings.Fields(line)\n\n    fmt.Println(\"Words:\", len(words))\n    fmt.Println(\"First word:\", words[0]) \/\/ [0] is the first item in the list\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Go makes simple programs<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Type a sentence: Words: 4\nFirst word: Go<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First, <code>ReadString<\/code> reads the whole line, spaces and all. Then <code>strings.Fields<\/code> cuts it into words wherever it finds spaces. Finally, <code>len<\/code> counts the words, and <code>words[0]<\/code> picks the first one.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 8: Convert Text to a Number with strconv<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Line readers give you text. To do maths, convert it with <code>strconv.Atoi<\/code>, which also reports bad input.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"bufio\"\n    \"fmt\"\n    \"os\"\n    \"strconv\" \/\/ strconv converts between text and numbers\n    \"strings\"\n)\n\n\/\/ main reads a price as text, turns it into a number and adds 18% GST\nfunc main() {\n    reader := bufio.NewReader(os.Stdin)\n    fmt.Print(\"Enter price: \")\n    text, _ := reader.ReadString('\\n')\n\n    \/\/ Atoi means \"ASCII to integer\"; it returns the number and an error\n    price, err := strconv.Atoi(strings.TrimSpace(text))\n    if err != nil {\n        fmt.Println(\"Error:\", err)\n        return\n    }\n\n    withTax := price * 118 \/ 100 \/\/ 100% of the price plus 18% tax\n    fmt.Println(\"Price with 18% GST:\", withTax)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>500<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter price: Price with 18% GST: 590<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the user typed &#8220;five hundred&#8221;, <code>Atoi<\/code> would return the error <code>strconv.Atoi: parsing \"five hundred\": invalid syntax<\/code>. So the check keeps the program safe.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Formatted Go User Input with Scanf and Sscan<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes Go user input has a fixed shape, such as a date or &#8220;name age&#8221;. The <code>Scanf<\/code> and <code>Sscan<\/code> family can read it in one step.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 9: Read a Date with Scanf<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Scanf<\/code> uses verbs like <code>Printf<\/code>. Any other text in the format, such as the dashes here, must match the input exactly.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ main reads a date typed as dd-mm-yyyy\nfunc main() {\n    var day, month, year int\n    fmt.Print(\"Enter date (dd-mm-yyyy): \")\n\n    \/\/ each %d reads one whole number; the dashes must appear in the input too\n    fmt.Scanf(\"%d-%d-%d\", &amp;day, &amp;month, &amp;year)\n\n    fmt.Printf(\"Day %d, Month %d, Year %d\\n\", day, month, year)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>15-08-2026<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter date (dd-mm-yyyy): Day 15, Month 8, Year 2026<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>%d<\/code> read &#8220;08&#8221; as 8, because a number has no leading zeros. The dashes in the format matched the dashes in the input.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 10: Parse a String with Sscan<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Sscan<\/code> reads from a string instead of the keyboard. It is handy when you already have a line of text.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ main pulls a name, an age and a weight out of one string\nfunc main() {\n    record := \"Ravi 30 72.5\"\n\n    var name string\n    var age int\n    var weight float64\n\n    \/\/ Sscan returns how many values it read (count) and err (the error value)\n    count, err := fmt.Sscan(record, &amp;name, &amp;age, &amp;weight)\n    fmt.Println(count, err)\n    fmt.Printf(\"%s is %d years old and weighs %.1f kg\\n\", name, age, weight)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>3 &lt;nil&gt;\nRavi is 30 years old and weighs 72.5 kg<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>count<\/code> is 3 because all three values were read. This program needs no keyboard, so it also runs in the Go Playground.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go User Input from the Command Line<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Command line arguments are another kind of Go user input. They are words you type after the program name. They are ready before <code>main<\/code> starts, so the program does not wait for the user.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 11: Sum Numbers from os.Args<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>os.Args<\/code> is a slice of strings. The first item is the program path, so your values start at index 1.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"os\"\n    \"strconv\"\n)\n\n\/\/ main adds every number typed after the program name\nfunc main() {\n    total := 0\n\n    \/\/ os.Args[1:] skips item 0 (the program path)\n    \/\/ range gives each word in turn; _ skips its position\n    for _, arg := range os.Args[1:] {\n        number, err := strconv.Atoi(arg)\n        if err != nil {\n            fmt.Println(\"Skipping\", arg)\n            continue \/\/ jump to the next word\n        }\n        total += number\n    }\n    fmt.Println(\"Sum:\", total)\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We run it with three numbers after the program name.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>go run . 10 20 30<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Sum: 60<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loop skips any word that is not a number. Our <a href=\"https:\/\/smitabharat.com\/blog\/go-for-loops-examples\/\">Go for loops guide<\/a> explains <code>range<\/code> in detail.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 12: Named Options with the flag Package<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>flag<\/code> package reads options like <code>-name=Asha<\/code>. It also gives default values and a help message for free.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"flag\" \/\/ flag reads named options such as -name=Meera\n    \"fmt\"\n)\n\n\/\/ main reads -name and -age options and prints a greeting\nfunc main() {\n    \/\/ each line gives: option name, default value, help text\n    name := flag.String(\"name\", \"Guest\", \"your name\")\n    age := flag.Int(\"age\", 18, \"your age\")\n\n    flag.Parse() \/\/ read the options from the command line\n\n    \/\/ name and age are pointers, so * gets the value they point to\n    fmt.Printf(\"Hello %s, you are %d\\n\", *name, *age)\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We pass both options when we run it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>go run . -name=Meera -age=28<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Hello Meera, you are 28<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>flag.String<\/code> returns a pointer, so we print <code>*name<\/code>. Without options, the program prints &#8220;Hello Guest, you are 18&#8221;. Our <a href=\"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/\">Go flag package guide<\/a> covers more option types.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go User Input: Scan vs bufio<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Beginners often ask which reader to use for Go user input. The diagram and table below compare the two most common choices.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-diagram-2-1024x640.png\" alt=\"Go user input comparison of fmt.Scan and bufio readers\" class=\"wp-image-733\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">fmt.Scan is quick for single words and numbers, while bufio reads whole lines and large input fast.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>fmt.Scan<\/th><th>bufio.Reader or Scanner<\/th><\/tr><\/thead><tbody><tr><td>Reads spaces in text<\/td><td>No, stops at a space<\/td><td>Yes, the full line<\/td><\/tr><tr><td>Converts to int for you<\/td><td>Yes<\/td><td>No, use strconv<\/td><\/tr><tr><td>Speed on big input<\/td><td>Slow<\/td><td>Fast<\/td><\/tr><tr><td>Error checking<\/td><td>Returns an error<\/td><td>Returns an error<\/td><\/tr><tr><td>Best for<\/td><td>Small programs<\/td><td>Lines, files and judges<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In short, use <code>fmt.Scan<\/code> for a few numbers, and <code>bufio<\/code> for full lines or large input.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Go User Input<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Forgetting the &amp;:<\/strong> <code>fmt.Scan(name)<\/code> cannot change <code>name<\/code>. Always pass <code>&amp;name<\/code>.<\/li>\n\n\n<li><strong>Expecting Scan to read spaces:<\/strong> it stops at the first space, so &#8220;Asha Mehta&#8221; becomes &#8220;Asha&#8221;.<\/li>\n\n\n<li><strong>Keeping the new line:<\/strong> <code>ReadString('\\n')<\/code> keeps it, so trim the text before you compare it.<\/li>\n\n\n<li><strong>Ignoring errors:<\/strong> a letter typed into an int gives zero, so check <code>err<\/code> every time.<\/li>\n\n\n<li><strong>Mixing bufio and fmt.Scan:<\/strong> <code>bufio<\/code> reads ahead into its buffer, so a later <code>fmt.Scan<\/code> can find nothing left to read.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Go User Input<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Check every error<\/strong>, so bad input never turns into wrong results.<\/li>\n\n\n<li><strong>Trim input with strings.TrimSpace<\/strong>, which also fixes Windows line endings.<\/li>\n\n\n<li><strong>Choose one reader per program<\/strong>, rather than mixing <code>fmt.Scan<\/code> and <code>bufio<\/code>.<\/li>\n\n\n<li><strong>Prefer bufio.Scanner for big input<\/strong>, because it is much faster in coding tests.<\/li>\n\n\n<li><strong>Print a clear prompt<\/strong>, so the user knows what to type.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Go User Input Interview Questions and Answers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These Go user input questions come up often in interviews. We show the input and the real output for every program, tested on Go 1.27.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">fmt.Scan Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1. Why do we write &amp;name in fmt.Scan(&amp;name)?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Scan<\/code> must change your variable, so it needs its memory address. In Go, arguments are copied. Without <code>&amp;<\/code>, <code>Scan<\/code> would only get a copy and could not fill the real variable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ main reads one word and prints it\nfunc main() {\n    var first string\n    fmt.Scan(&amp;first) \/\/ Scan stops at the first space\n    fmt.Println(\"Got:\", first)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Asha Mehta<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Got: Asha<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Scan<\/code> stops at the first space, so only &#8220;Asha&#8221; is stored. Use <code>bufio.Reader<\/code> to read the full line.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3. What is the difference between Scan, Scanln and Scanf?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Scan<\/code> treats new lines like spaces. <code>Scanln<\/code> stops at the end of the line, even if some variables are still empty. <code>Scanf<\/code> reads values in a pattern you give it, such as <code>%d-%d<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ main tries to read two numbers from one line\nfunc main() {\n    var first, second int\n    count, err := fmt.Scanln(&amp;first, &amp;second) \/\/ count is how many values were read\n    fmt.Println(count, err, first, second)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>5<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1 unexpected newline 5 0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Scanln<\/code> read 5, then hit the end of the line before it found a second number. So it returns 1 and an &#8220;unexpected newline&#8221; error, and <code>second<\/code> stays 0.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5. What happens if you type a decimal into an int with Scan?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ main reads a whole number and prints it with the error value\nfunc main() {\n    var number int\n    _, err := fmt.Scan(&amp;number)\n    fmt.Println(number, err)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>3.7<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>3 &lt;nil&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Scan<\/code> reads the 3 and stops at the dot, because a dot cannot be part of an int. The rest, &#8220;.7&#8221;, stays in the input for the next read. Always validate input that must be a whole number.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">bufio and Line Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6. Why does my string comparison fail after ReadString?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>ReadString('\\n')<\/code> keeps the new line, and Windows also adds <code>\\r<\/code>. So &#8220;yes\\r\\n&#8221; is not equal to &#8220;yes&#8221;. Fix it with <code>strings.TrimSpace(line)<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"bufio\"\n    \"fmt\"\n    \"os\"\n)\n\n\/\/ main shows the bug you get when you mix bufio and fmt.Scan\nfunc main() {\n    reader := bufio.NewReader(os.Stdin)\n    name, _ := reader.ReadString('\\n') \/\/ reads ahead into its own buffer\n\n    var age int\n    _, err := fmt.Scan(&amp;age) \/\/ reads os.Stdin directly, but it is already empty\n\n    \/\/ %q shows the text in quotes, so you can see the hidden \\n\n    fmt.Printf(\"name=%q age=%d err=%v\\n\", name, age, err)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Asha\n25<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>name=\"Asha\\n\" age=0 err=EOF<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here the input comes from a pipe, as in a coding test. <code>bufio.Reader<\/code> reads a big block into its own buffer, so it took &#8220;25&#8221; as well. When <code>fmt.Scan<\/code> then reads <code>os.Stdin<\/code> directly, nothing is left, and it returns <code>EOF<\/code>. When you type line by line in a terminal, it may seem to work, which makes this bug hard to find. So never mix <code>bufio<\/code> and <code>fmt.Scan<\/code> on the same input.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8. What is the line limit of bufio.Scanner?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By default, one line can be up to 64 KB (<code>bufio.MaxScanTokenSize<\/code>). For longer lines, call <code>scanner.Buffer<\/code> with a bigger buffer, or <code>Scan<\/code> stops with an error.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9. How do you read words instead of lines with bufio.Scanner?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Call <code>scanner.Split(bufio.ScanWords)<\/code> before the loop. Then each <code>Scan<\/code> returns one word.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"bufio\"\n    \"fmt\"\n    \"os\"\n)\n\n\/\/ main counts every word in the input\nfunc main() {\n    scanner := bufio.NewScanner(os.Stdin)\n    scanner.Split(bufio.ScanWords) \/\/ read one word at a time instead of one line\n\n    words := 0\n    for scanner.Scan() {\n        words++\n    }\n    fmt.Println(\"Words:\", words)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Go is simple\nand fast<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Words: 5<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The input has five words over two lines. With <code>ScanWords<\/code>, each loop reads one word, so <code>words<\/code> ends at 5.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10. How do you know when input has ended?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>scanner.Scan()<\/code> returns false, and <code>scanner.Err()<\/code> is nil if the end was normal. With <code>fmt.Scan<\/code>, the error is <code>io.EOF<\/code>. The user can send the end of input with Ctrl+D on Linux and macOS, or Ctrl+Z then Enter on Windows.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Conversion and Command Line Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strconv\"\n)\n\n\/\/ main tries to convert two strings that are not clean numbers\nfunc main() {\n    first, err := strconv.Atoi(\"42abc\") \/\/ letters after the digits\n    fmt.Println(first, err)\n\n    second, err := strconv.Atoi(\" 42\") \/\/ a space before the digits\n    fmt.Println(second, err)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>0 strconv.Atoi: parsing \"42abc\": invalid syntax\n0 strconv.Atoi: parsing \" 42\": invalid syntax<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Atoi<\/code> needs the whole string to be a number. Even one space breaks it, so trim input first.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12. What does this program print with go run . red green?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"os\"\n)\n\n\/\/ main counts the words after the program name and prints them\nfunc main() {\n    fmt.Println(len(os.Args) - 1) \/\/ minus 1 because item 0 is the program path\n    fmt.Println(os.Args[1:])      \/\/ [1:] means \"from item 1 to the end\"\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>2\n[red green]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>os.Args<\/code> has three items, the program path plus two words. So <code>len(os.Args) - 1<\/code> gives the real count of 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13. What is the difference between os.Args and the flag package?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>os.Args<\/code> gives you raw words in order. The <code>flag<\/code> package reads named options, sets defaults and prints help with <code>-h<\/code>. Use <code>flag<\/code> for any tool other people will run.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14. How do you read a float from input?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>fmt.Scan(&amp;price)<\/code> with a <code>float64<\/code> variable. With a line reader, use <code>strconv.ParseFloat(text, 64)<\/code> instead.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ main reads two numbers separated by a comma from a string\nfunc main() {\n    var first, second int\n    count, _ := fmt.Sscanf(\"7,8\", \"%d,%d\", &amp;first, &amp;second)\n    fmt.Println(count, first*second)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>2 56<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The comma in the format matches the comma in the text. So both numbers are read, and 7 times 8 is 56.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16. How do you read a password without showing it?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The standard library has no hidden input. The usual choice is <code>term.ReadPassword<\/code> from the <code>golang.org\/x\/term<\/code> module. It turns off the echo while the user types.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17. How do you read input fast in a coding test?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Wrap standard input with <code>bufio.NewReader<\/code> or <code>bufio.Scanner<\/code>, and wrap output with <code>bufio.NewWriter(os.Stdout)<\/code>. Remember to call <code>Flush<\/code> on the writer at the end, or some output is lost.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18. Can the Go Playground read user input?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. The Playground has no standard input, so <code>fmt.Scan<\/code> gets <code>io.EOF<\/code> at once. Use <code>Sscan<\/code> on a fixed string, or an online compiler with an input box, to test these programs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This task mixes two kinds of Go user input. Write a program that reads a student&#8217;s name on the first line and three marks on the second line. Then print the total and the average with one decimal place. Hint: read the name with <code>bufio.Reader<\/code>, then use <code>fmt.Sscan<\/code> on the second line.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pkg.go.dev\/fmt#hdr-Scanning\">fmt package: scanning<\/a><\/li>\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/bufio\">bufio package documentation<\/a><\/li>\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/strconv\">strconv package documentation<\/a><\/li>\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/flag\">flag package documentation<\/a><\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go user input comes from standard input, command line arguments or pipes.<\/li>\n\n\n<li><code>fmt.Scan<\/code> reads words and converts types, but stops at spaces.<\/li>\n\n\n<li><code>bufio.Reader<\/code> and <code>bufio.Scanner<\/code> read whole lines and handle big input fast.<\/li>\n\n\n<li><code>strconv.Atoi<\/code> turns text into numbers and reports bad input.<\/li>\n\n\n<li><code>os.Args<\/code> and the <code>flag<\/code> package read values from the command line.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now that your programs can read numbers, let&#8217;s do real calculations with them. Read <a href=\"https:\/\/smitabharat.com\/blog\/go-basic-math-programs\/\">Go basic math programs with output<\/a>. For a refresher on the operators we use there, see <a href=\"https:\/\/smitabharat.com\/blog\/go-operators-examples\/\">Go operators explained with examples<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go user input programs let your code ask a question and use the answer, which is the moment a program starts to feel alive.&hellip;<\/p>\n","protected":false},"author":1,"featured_media":734,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[106],"tags":[96,95,11,104,108],"swapz_series":[],"class_list":["post-736","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-programs","tag-beginner","tag-go-interview-questions","tag-go-lang","tag-go-programs","tag-go-user-input"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go User Input: fmt.Scan, bufio and os.Args<\/title>\n<meta name=\"description\" content=\"Learn Go user input with fmt.Scan, bufio, Sscan, os.Args and flag, with sample input, exact output and input interview questions with answers.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-user-input-programs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go User Input: fmt.Scan, bufio and os.Args\" \/>\n<meta property=\"og:description\" content=\"Learn Go user input with fmt.Scan, bufio, Sscan, os.Args and flag, with sample input, exact output and input interview questions with answers.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-user-input-programs\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-04T05:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-28T19:59:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"19 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-user-input-programs\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-user-input-programs\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go User Input Programs: fmt.Scan, bufio and os.Args\",\"datePublished\":\"2026-10-04T05:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-user-input-programs\\\/\"},\"wordCount\":2255,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-user-input-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-user-input-programs-featured.png\",\"keywords\":[\"Beginner\",\"Go Interview Questions\",\"Go Lang\",\"Go Programs\",\"Go User Input\"],\"articleSection\":[\"Go Programs\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-user-input-programs\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-user-input-programs\\\/\",\"name\":\"Go User Input: fmt.Scan, bufio and os.Args\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-user-input-programs\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-user-input-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-user-input-programs-featured.png\",\"datePublished\":\"2026-10-04T05:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:43+00:00\",\"description\":\"Learn Go user input with fmt.Scan, bufio, Sscan, os.Args and flag, with sample input, exact output and input interview questions with answers.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-user-input-programs\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-user-input-programs\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-user-input-programs\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-user-input-programs-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-user-input-programs-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go User Input featured image: prompt reading a name and command line numbers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-user-input-programs\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go User Input Programs: fmt.Scan, bufio and os.Args\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go User Input: fmt.Scan, bufio and os.Args","description":"Learn Go user input with fmt.Scan, bufio, Sscan, os.Args and flag, with sample input, exact output and input interview questions with answers.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-user-input-programs\/","og_locale":"en_US","og_type":"article","og_title":"Go User Input: fmt.Scan, bufio and os.Args","og_description":"Learn Go user input with fmt.Scan, bufio, Sscan, os.Args and flag, with sample input, exact output and input interview questions with answers.","og_url":"https:\/\/smitabharat.com\/blog\/go-user-input-programs\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-10-04T05:30:00+00:00","article_modified_time":"2026-11-28T19:59:43+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"19 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-user-input-programs\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-user-input-programs\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go User Input Programs: fmt.Scan, bufio and os.Args","datePublished":"2026-10-04T05:30:00+00:00","dateModified":"2026-11-28T19:59:43+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-user-input-programs\/"},"wordCount":2255,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-user-input-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-featured.png","keywords":["Beginner","Go Interview Questions","Go Lang","Go Programs","Go User Input"],"articleSection":["Go Programs"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-user-input-programs\/","url":"https:\/\/smitabharat.com\/blog\/go-user-input-programs\/","name":"Go User Input: fmt.Scan, bufio and os.Args","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-user-input-programs\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-user-input-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-featured.png","datePublished":"2026-10-04T05:30:00+00:00","dateModified":"2026-11-28T19:59:43+00:00","description":"Learn Go user input with fmt.Scan, bufio, Sscan, os.Args and flag, with sample input, exact output and input interview questions with answers.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-user-input-programs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-user-input-programs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-user-input-programs\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-user-input-programs-featured.png","width":2400,"height":1260,"caption":"Go User Input featured image: prompt reading a name and command line numbers"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-user-input-programs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go User Input Programs: fmt.Scan, bufio and os.Args"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/736","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=736"}],"version-history":[{"count":2,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/736\/revisions"}],"predecessor-version":[{"id":870,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/736\/revisions\/870"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/734"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=736"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}