sebas Posted December 12, 2009 at 12:43 AM Report Share #299976 Posted December 12, 2009 at 12:43 AM Eu não precebo muito disto, pois so tenho programação ha 2 meses e para projecto final tenho que fazer o "lifegame". Os professores deram umas ajudas mas o meu programa esta a dar um erro e n sei qual é. Podem me ajudar? No main.c: ...(um pequeno excerto) imprime(game, dimx, dimy); //evoluir a matriz /* while(1) { evolui( game,dimx,dimy); imprime(game,dimx,dimy); //verificar se carregaou nalguma tecla if( kbhit()) break; } */ //libertar a memoria da matriz liberta( game, dimy); return 0; } e na biblioteca int numVivos( char**game,int dimx, int dimy, int x, int y) { int count = 0; for (py=1;py<dimy-1;py++) { for (px=1;px<dimy-1;px++) { //1ª linha if(game[y-1][x-1]=='o') count++; if(game[y-1][x]=='o') count++; if(game[y-1][x+1]=='o') count++; // 2ª linha if(game[y][x-1]=='o') count++; if(game[y][x+1]=='o') count++; if(game[y+1][x+1]=='o') count++; if(game[y+1][x]=='o') count++; if(game[y+1][x-1]=='o') count++; } } // contar as celulas vivas return count; } void evolui( char ** game,int dimx, int dimy) { char **tmp; int x,y, vivas; //alocar memoria para o jogo tempoarario tmp = aloca(dimx, dimy); //inicializar as celulas limpa( tmp, dimx,dimy); //percorrer todas as linhas for (y=1; y<dimx-1; y++) { //percorrer todas as colunas for (x=1; x<dimx-1; x++) { vivas = numVivos(game,dimx,dimy,x,y); if(vivas<2) tmp [y][x]='.'; if(vivas>3) tmp [y][x]='.'; if(vivas==3) tmp [y][x]='x'; if(vivas==2) tmp [y][x]=game [y][x]; } } /* //copiar o tmp para o game for(y=0; y < dimy; y++) { for( x=0; x < dimx; x++) { game[y][x] = tmp[y][x]; } } *///libertar o tmp liberta(tmp,dimy); } mas o meu programa dá me 4 erros no "int numVivos" C:\Users\Sebastião\Desktop\C\life\LifeGame.c:96: error: `py' undeclared (first use in this function) C:\Users\Sebastião\Desktop\C\life\LifeGame.c:96: error: (Each undeclared identifier is reported only once C:\Users\Sebastião\Desktop\C\life\LifeGame.c:96: error: for each function it appears in.) C:\Users\Sebastião\Desktop\C\life\LifeGame.c:98: error: `px' undeclared (first use in this function) o que esta mal? Podem explicar o que posso fazer? Link to comment Share on other sites More sharing options...
TheDark Posted December 12, 2009 at 03:40 AM Report Share #299982 Posted December 12, 2009 at 03:40 AM Se leres bem as mensagens de erro, está lá tudo dito: as variáveis py e px não foram declaradas. Tudo o que tens que fazer é declará-las no início da função. Desaparecido. Link to comment Share on other sites More sharing options...
sebas Posted December 12, 2009 at 02:29 PM Author Report Share #300015 Posted December 12, 2009 at 02:29 PM Obrigado. Mas o meu mal é que estava a declarar dentro do "int numVivos". Depois pus assim "int count=0, py, px;" e ja deu. Obrigado. Alguem sabe alguma função para atrazar o ciclo. Tipo, tenho um while e quero que so se repita em 5 5 segundos. ? Link to comment Share on other sites More sharing options...
Localhost Posted December 13, 2009 at 11:27 AM Report Share #300133 Posted December 13, 2009 at 11:27 AM Chama uma função system, em Linux tem a função sleep... Ah, também existe a função sleep na biblioteca windows.h acho eu! here since 2009 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