Jump to content

Duas dúvidas simples relativamente ao uso de malloc() e realloc()

Guest id194

Recommended Posts

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.