polska Posted July 27, 2012 at 12:00 PM Report Share #470623 Posted July 27, 2012 at 12:00 PM Boas pessoal, estava a usar o memset em 3 arrays de ints: memset(first, 1, sizeof(first)) memset(on, -1, sizeof(on)) memset(off, -1, sizeof(on)) Os dois últimos memset funcionaram e os arrays ficaram com -1, mas o primeiro fica com números esquesitos, tipo 164165948... Alguma ajuda? Corrige um sábio e ele mais sábio ficará. Corrige um ignorante e um inimigo ganharás. Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted July 27, 2012 at 12:03 PM Report Share #470625 Posted July 27, 2012 at 12:03 PM podes por todo o código que vem antes ... principalmente a declaração dos arrays e alguma inicialização que por ventura terás ? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
pmg Posted July 27, 2012 at 12:11 PM Report Share #470628 Posted July 27, 2012 at 12:11 PM tipo 164165948 Será 16843009? 16843009, em binário, é 1000000010000000100000001 2 Report What have you tried? Não respondo a dúvidas por PM A minha bola de cristal está para compor; deve ficar pronta para a semana. Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código! Link to comment Share on other sites More sharing options...
polska Posted July 27, 2012 at 12:26 PM Author Report Share #470630 Posted July 27, 2012 at 12:26 PM (edited) podes por todo o código que vem antes ... principalmente a declaração dos arrays e alguma inicialização que por ventura terás ? #include <stdio.h> #include <string.h> int main() { int lamps[10], on[2], off[2]; int N, C, input, last, i, k; memset(lamps, 1, sizeof(lamps)); memset(on, -1, sizeof(on)); memset(off, -1, sizeof(off)); Não tenho inicialização nenhum relativamente aos arrays, apenas tenho o memset Será 16843009? 16843009, em binário, é 1000000010000000100000001 Sim, é isso mesmo xD , não dá para colocar 1? Edited July 27, 2012 at 12:27 PM by polska Corrige um sábio e ele mais sábio ficará. Corrige um ignorante e um inimigo ganharás. Link to comment Share on other sites More sharing options...
mogers Posted July 27, 2012 at 12:43 PM Report Share #470631 Posted July 27, 2012 at 12:43 PM Sim, é isso mesmo xD , não dá para colocar 1? Não. O memset funciona ao nível dos bytes (8 bits) e os ints são 4 bytes (32 bits). Os únicos que funcionam são o 0 e o -1 porque 0 é representado como 32 bits a 0 e o -1 é representado como 32 bits a 1. 1 Report "What we do for ourselves dies with us. What we do for others and the world, remains and is immortal.", Albert Pine Blog pessoal : contém alguns puzzles, algoritmos e problemas para se resolver com programação. Link to comment Share on other sites More sharing options...
polska Posted July 27, 2012 at 12:59 PM Author Report Share #470632 Posted July 27, 2012 at 12:59 PM (edited) Não. O memset funciona ao nível dos bytes (8 bits) e os ints são 4 bytes (32 bits). Os únicos que funcionam são o 0 e o -1 porque 0 é representado como 32 bits a 0 e o -1 é representado como 32 bits a 1. Obrigado 😉, e ao pmg e Happy também. Edited July 27, 2012 at 01:00 PM by polska Corrige um sábio e ele mais sábio ficará. Corrige um ignorante e um inimigo ganharás. 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