mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.1 KiB
1.1 KiB
basicatoi
Instructions
-
Write a function that simulates the behaviour of the
Atoi
function in Go.Atoi
transforms a number defined as astring
in a number defined as anint
. -
Atoi returns
0
if thestring
is not considered as a valid number. For this exercise only validstring
will be tested. They will only contain one or several digits as characters. -
For this exercise the handling of the signs
+
or-
does not have to be taken into account. -
This function will only have to return the
int
. For this exercise theerror
return ofAtoi
is not required.
Expected function
func BasicAtoi(s string) int {
}
Usage
Here is a possible program to test your function :
package main
import (
"fmt"
piscine ".."
)
func main() {
fmt.Println(piscine.BasicAtoi("12345"))
fmt.Println(piscine.BasicAtoi("0000000012345"))
fmt.Println(piscine.BasicAtoi("000000"))
}
And its output :
student@ubuntu:~/basicatoi/test$ go build
student@ubuntu:~/basicatoi/test$ ./test
12345
12345
0
student@ubuntu:~/basicatoi/test$