-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.go
61 lines (46 loc) · 1.09 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
//Import packages
import (
"bufio"
"encoding/csv"
"fmt"
"log"
"os"
"strings"
)
//Funtion for logging errors
func errorHandler(err error) {
println("Ops, something went wrong:", err)
}
//Function to get attendance
func getStudentInfo() (name, roll, course string) {
fmt.Println("Enter the student name:")
inputReader := bufio.NewReader(os.Stdin)
name, _ = inputReader.ReadString('\n')
fmt.Println("Enter the student roll number:")
inputReader = bufio.NewReader(os.Stdin)
roll, _ = inputReader.ReadString('\n')
fmt.Println("Enter the course:")
inputReader = bufio.NewReader(os.Stdin)
course, _ = inputReader.ReadString('\n')
return strings.TrimSpace(name), strings.TrimSpace(roll), strings.TrimSpace(course)
}
//Main
func main() {
name, roll, course := getStudentInfo()
record := []string{name, roll, course}
file, err := os.Create("attendance.txt")
if err != nil {
errorHandler(err)
log.Fatalf("%s", err)
}
w := csv.NewWriter(file)
defer file.Close()
w.Write(record)
w.Flush()
err = w.Error()
if err != nil {
errorHandler(err)
log.Fatalf("%s", err)
}
}