Created
January 26, 2015 20:19
-
-
Save mauricioaniche/83a9b17ad588b37d9431 to your computer and use it in GitHub Desktop.
Foge Foge - Matriz - Final
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include "fogefoge.h" | |
char** mapa; | |
int linhas; | |
int colunas; | |
void lemapa() { | |
FILE* f; | |
f = fopen("mapa.txt", "r"); | |
if(f == 0) { | |
printf("Erro na leitura do mapa"); | |
exit(1); | |
} | |
fscanf(f, "%d %d", &linhas, &colunas); | |
alocamapa(); | |
for(int i = 0; i < 5; i++) { | |
fscanf(f, "%s", mapa[i]); | |
} | |
fclose(f); | |
} | |
void alocamapa() { | |
mapa = malloc(sizeof(char*) * linhas); | |
for(int i = 0; i < linhas; i++) { | |
mapa[i] = malloc(sizeof(char) * colunas + 1); | |
} | |
} | |
void liberamapa() { | |
for(int i = 0; i < linhas; i++) { | |
free(mapa[i]); | |
} | |
free(mapa); | |
} | |
int main() { | |
lemapa(); | |
for(int i = 0; i < linhas; i++) { | |
printf("%s\n", mapa[i]); | |
} | |
liberamapa(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void alocamapa(); | |
void lemapa(); | |
void liberamapa(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 10 | |
|--------| | |
|...|..-.| | |
|..-|.@..| | |
|......-.| | |
|--------| |
A alocação dinâmica de memória parece muito interessante.
Ok, o jogo está começando a ficar complexo.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Muito ineressante.