Upper Posted December 7, 2009 at 11:03 PM Report Share #299161 Posted December 7, 2009 at 11:03 PM boas Como e que eu insiro um inteiro numa parcela de uma estrutura? uma funcao exemplo que tenho e a seguinte void X ( char * local, int * num) { puts(local); local = *num; } mas esta a dizer que tenho mal inserido o parametro local..alguem pode ajudar? Link to comment Share on other sites More sharing options...
bosnia Posted December 7, 2009 at 11:32 PM Report Share #299166 Posted December 7, 2009 at 11:32 PM http://publications.gbdirect.co.uk/c_book/chapter6/structures.html Link to comment Share on other sites More sharing options...
Upper Posted December 8, 2009 at 02:42 PM Author Report Share #299252 Posted December 8, 2009 at 02:42 PM Ja li tudo mas nao consegui.me explicar o meu problema. No codigo que fiz da.me um erro que e comparacao entre um pointer e um integrant mas ja tentei de todas as maneiras mas nao consegui resolver. Alguem pode me ajudar? Link to comment Share on other sites More sharing options...
Baderous Posted December 8, 2009 at 02:44 PM Report Share #299253 Posted December 8, 2009 at 02:44 PM Estás a atribuir a um apontador para caracter um valor inteiro que é dado pelo apontador para inteiro. Link to comment Share on other sites More sharing options...
Upper Posted December 8, 2009 at 02:45 PM Author Report Share #299255 Posted December 8, 2009 at 02:45 PM O apontador de caracter e a localizacao onde um tenho que por esse inteiro. Link to comment Share on other sites More sharing options...
Baderous Posted December 8, 2009 at 02:59 PM Report Share #299259 Posted December 8, 2009 at 02:59 PM Eu sei mas os tipos são incompatíveis: local: char* *num: int Link to comment Share on other sites More sharing options...
Upper Posted December 8, 2009 at 03:01 PM Author Report Share #299261 Posted December 8, 2009 at 03:01 PM Entao como e que eu fazendo por exemplo le_int( /*Enderenço da estrutura*/, 10) como e que eu posso por o numero 10 no endereço da estrutura? Link to comment Share on other sites More sharing options...
Baderous Posted December 8, 2009 at 03:08 PM Report Share #299264 Posted December 8, 2009 at 03:08 PM Convertes o número para string e fazes a atribuição. Ou então mudas o tipo de 'local'. Link to comment Share on other sites More sharing options...
Upper Posted December 8, 2009 at 03:09 PM Author Report Share #299265 Posted December 8, 2009 at 03:09 PM void X ( char * local, char * num) { puts(local); gets(num); } Assim pode ser? Link to comment Share on other sites More sharing options...
Upper Posted December 8, 2009 at 03:14 PM Author Report Share #299266 Posted December 8, 2009 at 03:14 PM MAs ao mudar o tipo do local fica por exemplo void X ( int * local, int * num) { *local = *num; } Link to comment Share on other sites More sharing options...
Baderous Posted December 8, 2009 at 03:19 PM Report Share #299268 Posted December 8, 2009 at 03:19 PM MAs ao mudar o tipo do local fica por exemplo void X ( int * local, int * num) { *local = *num; } Sim. Link to comment Share on other sites More sharing options...
Upper Posted December 8, 2009 at 03:29 PM Author Report Share #299271 Posted December 8, 2009 at 03:29 PM Nao existe nenhuma forma de ser char *local e int * num? Link to comment Share on other sites More sharing options...
Baderous Posted December 8, 2009 at 03:45 PM Report Share #299275 Posted December 8, 2009 at 03:45 PM Existe e já te indiquei: converte o inteiro numa string e depois fazes a atribuição com o strdup ou o strncpy dependendo se a memória para o local já está alocada ou não. 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