Guest id194 Posted April 3, 2007 at 10:57 AM Report Share #91604 Posted April 3, 2007 at 10:57 AM 1) coiso = malloc(5 * sizeof(char*)); e depois se precisar de + 3, por exemplo, faria: coiso = realloc(coiso, 3 * sizeof(char *)); ou coiso = realloc(coiso, 8 * sizeof(char *)); 2) fileList = malloc(strlen((dpItem->d_name) + 1) * sizeof(char)); Visto o sizeof(char) ser igual a 1, eu estou a multiplicar o comprimento da string por 1, o que vai dar o próprio comprimento da string. Não faz lógica nenhuma ter ali o sizeof(char) pois n? Link to comment Share on other sites More sharing options...
shumy Posted April 3, 2007 at 11:14 AM Report Share #91612 Posted April 3, 2007 at 11:14 AM 1) O correcto é: coiso = realloc(coiso, 8 * sizeof(char *)); 2) Em principio sizeof(char) será em geral 1 byte, mas não convem partir desse pressuposto, já que o tamanho dos tipos pode depender da arquitectura da máquina. Aqui há coisa de 2 anos fazia umas malhas de croché, depois fartei-me e fui para informática! Link to comment Share on other sites More sharing options...
Guest id194 Posted April 3, 2007 at 11:31 AM Report Share #91619 Posted April 3, 2007 at 11:31 AM ok thanks... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now