VOOZH about

URL: https://www.geeksforgeeks.org/go-language/fmt-sscanln-function-in-golang-with-examples/

⇱ fmt.Sscanln() Function in Golang With Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

fmt.Sscanln() Function in Golang With Examples

Last Updated : 5 May, 2020
In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.Sscanln() function in Go language scans the specified string and stores the successive space-separated values into successive arguments. This function stops scanning at a newline and after the final item, there must be a newline or EOF. Moreover, this function is defined under the fmt package. Here, you need to import the "fmt" package in order to use these functions. Syntax:
func Sscanln(str string, a ...interface{}) (n int, err error)
Parameters: This function accepts two parameters which are illustrated below:
  • str string: This parameter contains the specified text which is going to be scanned.
  • a ...interface{}: This parameter receives each elements of the string.
Returns: It returns the number of items successfully scanned. Example 1: Output:
n: 2, name: GFG, alphabet_count: 3
Example 2: Output:
name: GFG, alphabet_count: 0
In the above example, it can be seen that the assigned value of alphabet_count was 3 still the output is 0 this is because of there is new line (\n) in between two elements "GFG" and "alphabet_count" and hence this function stop scanning at a newline.
Comment
Article Tags:

Explore