FAQ
Read this: https://blog.golang.org/slices :)


On Friday, December 4, 2015 at 2:21:36 PM UTC+8, culver...@gmail.com wrote:

Greetings,

I choose to learn and write a program in Go for a Programming class. I am
having a bit of trouble sorting my strings by alphabetical order. Here is
my code:

func main() {
fmt.Println("Enter 10 Names")
var names [10]string
for i := 0; i < 10; i++ {
in := bufio.NewReader(os.Stdin)
line, _ := in.ReadString('\n')
names[i] = line
}
fmt.Println("Print the names in the order they were entered.")
for j := 0; j < 10; j++ {
fmt.Println(names[j])
}
fmt.Println("Sort the names in alphabetical order, and print the sorted
list.")
sort.Strings(names)
fmt.Println(names)

I get the following error from my compiler: cannot use names (type
[10]String) as type []string in argument to sort.Strings.

Can someone point me in the right direction?

Thanks in advance!
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 7 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 4, '15 at 6:21a
activeDec 5, '15 at 7:48a
posts7
users5
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase