Fixed crashing without arguments

This commit is contained in:
raul 2024-02-12 12:04:28 +00:00
parent 92d4ff62f3
commit ca05ff2eba
2 changed files with 4 additions and 6 deletions

BIN
golangr/file-reader/file-reader Executable file

Binary file not shown.

View File

@ -8,8 +8,6 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
//"time"
//"strconv"
) )
type PlayerStats struct { type PlayerStats struct {
@ -26,8 +24,8 @@ var names = []string{}
var err error var err error
var guess string var guess string
var guessLetter rune var guessLetter rune
var filePath string = os.Args[1] var filePath string
var randWord string = getWord(filePath) var randWord string
var hiddenChars []string var hiddenChars []string
func scanLine() (line string) { func scanLine() (line string) {
@ -43,6 +41,8 @@ func main() {
fmt.Println("Usage: ./file-reader names.txt") fmt.Println("Usage: ./file-reader names.txt")
os.Exit(1) os.Exit(1)
} }
filePath = os.Args[1]
randWord = getWord(filePath)
for range randWord { for range randWord {
hiddenChars = append(hiddenChars, "_") hiddenChars = append(hiddenChars, "_")
@ -91,8 +91,6 @@ func gameStatus() {
func game() { func game() {
clear() clear()
//filePath := os.Args[1]
//randWord := getWord(filePath)
for { for {
gameStatus() gameStatus()
if player.lives < 0 { if player.lives < 0 {