0
I’m starting to learn go and need to populate the different structs with their values. I thought about creating an array of structs and trying to use a for to fill the fields but give an error of
invalid operation: p[1].burst[i] (type int does not support indexing)
The question is whether it is possible to do something of the kind to fill the values or if there is some other way of doing
package main
import (
"fmt"
)
type process struct{
burst int
t_chegada int
}
func main(){
p := make([]process,10)
var n_processo int
fmt.Printf("Número de Processo: ")
fmt.Scanf("%d", &n_processo)
for i := 0; i < n_processo; i++ {
fmt.Printf("Burst Processo P%d: ", i)
fmt.Scanf("%d\n", &p[1].burst[i])
fmt.Printf("Tempo de Chegada P%d: ", i)
fmt.Scanf("%d\n", &p[2].t_chegada[i])
}
}
I was having trouble understanding a little how it worked and your answer helped a lot. I was having trouble reading the user input and put
fmt.Scanf
for every i do. I don’t know if it’s the best way but it worked– Dhonrian