This is the input data:
Name Dept College
A1 CSE SR1
A2 CSE SR2
A3 ECE SR1
A4 EEE SR3
A5 ECE SR1
A6 MECH SR2
A7 CSE SR1
A8 EEE SR1
A9 ECE SR3
A10 MECH SR3
A11 EEE SR1
Expected output: If I filter the college name (for example: --flag=SR3
) the output should print under SR3
, what are the names and depts are there.
A4 EEE
A10 MECH
for
loop over the slice with one if
in it. Use Println to output the result.Sample code:
package main
import (
. "fmt"
"os"
)
type Record struct {
Name string
Department string
College string
}
func main() {
records := make([]Record, 0)
// add records
records = append(records, Record{"A1", "CSE", "SR1"})
...
// get filter from os.Args
filter := ...
for _, v := range records {
if v.College == filter {
Println(v.Name, v.Department)
}
}
}
P.S. If you ask yourself why the question is downvoted (not by me) - because it does not demonstrate the you actually tried to solve the problem. See https://stackoverflow.com/help/on-topic