c - Variable Persistence in Linked List -


I am creating a domino game and when the user adds a domino to the left, the domino is added but the function exits Has been added to Domino

For information:.

  • The fitxesJoc (link list) is domino of the game and passed for an indicative function (so that it keeps all games)
  • opcionesCorrectas (Domino ) Is the correct option for domino

    • infer is included in the small number of domino
    • large number of superior dominoes
    • position
  • opcionFitxa (integer) player

  • ultimaFitxa-> SEG 'next' node
 tNode * ultimaFitxa = (tNode *) malloc's choice (include sizeof (tNode)); UltimaFitxa-> info.inferior = opcionesCorrectas [opcionFitxa - 1]. Upper; UltimaFitxa-> info.superior = opcionesCorrectas [opcionFitxa - 1]. Super; UltimaFitxa-> info.pos = opcionesCorrectas [opcionFitxa - 1] .pos; UltimaFitxa-> seg = fitxesJoc; FitxesJoc = ultimaFitxa; 

function

  unsigned int demanar_fitxa_tirar (tJugador * jugador, tNode * fitxesJoc, tPartida * top partida, tPila * fitxesBarrejades, bool primerCop)  

Function Call

  resultado = demanar_fitxa_tirar (& Jugadors [jugadorActual], fitxesJoc, part, fitxesBarrejades, true);  

In this way, I add dominoes to the top of the other dominoes.

The problem is that the demanar_fitxa_tirar to the last line:

  fitxesJoc = ultimaFitxa;  

Specifying a local variable, which has no effect on the calling code. You need to give a pointer to the calling code fitxesJoc , like this:

  unsigned int demanar_fitxa_tirar (..., tNode ** fitxesJoc, ...) // Additional note * {// ... * fitxesJoc = ultimaFitxa; // note additional *} zero main program () {tNode * fitxesJoc; // ... resultado = demanar_fitxa_tirar (..., and fitxjok, ...); // Note Extra & amp; // ...}  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -