11. Go - Input Bufio

BUFIO METHOD


import "bufio"

import "os"


scanner := bufio.NewScanner(os.Stdin)

scanner.Scan()

variable := scanner.Text()

fmt.Println(variable)


FMT METHOD


var name string

var age int

fmt.Scanln(&name, &age)

fmt.println(name,age)

// this method doesnt count white spaces


Increasing line buffer read size limit:

const maxCapacity = 512 * 1024 // max capacity

buf := make([]byte, maxCapacity) // buffer

scanner.Buffer(buf, maxCapacity) // put before scanning

Comments

Popular posts from this blog

2. FreeCodeCamp - Dynamic Programming - Learn to Solve Algorithmic Problems & Coding Challenges

20. Data Analytics - Analyze Data to Answer Questions - Week 1

3. Algorithms - Selection Sort