doushai4890 2019-08-18 10:06
浏览 101

标识符字符无效,文件名“插入”

I'm new in Go and writing a simple insertion sort but when i change my fileName to "insertion.go" I got error:

invalid identifier character U+00A0 at insertion.go:2:1

but when I change the filename to anything else it works fine:

insertion.go

package main

import (
        "fmt"
        "math/rand"
        "time"
)

func main() {
    slice := generateSlice(20)
    fmt.Println("
--- Unsorted --- 

", slice)
    insertionsort(slice)
    fmt.Println("
--- Sorted ---

", slice, "
")
}

func generateSlice(size int) []int {
    slice := make([]int, size, size)
    rand.Seed(time.Now().UnixNano())
    for i := 0; i < size; i++ {
    slice[i] = rand.Intn(999) - rand.Intn(999)
    }
    return slice
}

func insertionsort(items []int) {
    var n = len(items)
    for i := 1; i < n; i++ {
        j := i
        for j > 0 {
        if items[j-1] > items[j] {
            items[j-1], items[j] = items[j], items[j-1]
        }
        j = j - 1
        }
    }
}

I want to know what's the problem with name "insertion"?

  • 写回答

1条回答 默认 最新

  • douhuan6065 2019-08-18 10:12
    关注

    Please read the error carefully. Look where the error is occurring: line 2, character 1. That means you have some invalid character in your source file. It's not a problem with the filename. U+00A0 is a NO-BREAK SPACE, meaning you have an invalid no-break space character in your file, which will appear as invisible.

    So apparently, you have the following contents:

    package main
    X
    import (
    

    Where X is an (invisible) NO-BLOCK SPACE (aka &nbsp; in HTML speak).

    A guess would be that perhaps you copy-pasted this code from a web site, and a &nbsp; was erroneously included in the paste.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度