41 lines
		
	
	
		
			700 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			700 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| // For more tutorials: https://blog.learngoprogramming.com
 | |
| //
 | |
| // Copyright © 2018 Inanc Gumus
 | |
| // Learn Go Programming Course
 | |
| // License: https://creativecommons.org/licenses/by-nc-sa/4.0/
 | |
| //
 | |
| 
 | |
| package main
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 	"io/ioutil"
 | |
| 	"os"
 | |
| 	"sort"
 | |
| 	"strconv"
 | |
| )
 | |
| 
 | |
| func main() {
 | |
| 	items := os.Args[1:]
 | |
| 	if len(items) == 0 {
 | |
| 		fmt.Println("Send me some items and I will sort them")
 | |
| 		return
 | |
| 	}
 | |
| 
 | |
| 	sort.Strings(items)
 | |
| 
 | |
| 	var data []byte
 | |
| 	for i, s := range items {
 | |
| 		data = strconv.AppendInt(data, int64(i+1), 10)
 | |
| 		data = append(data, '.', ' ')
 | |
| 		data = append(data, s...)
 | |
| 		data = append(data, '\n')
 | |
| 	}
 | |
| 
 | |
| 	err := ioutil.WriteFile("sorted.txt", data, 0644)
 | |
| 	if err != nil {
 | |
| 		fmt.Println(err)
 | |
| 		return
 | |
| 	}
 | |
| }
 |