Created
January 26, 2015 20:19
-
-
Save mauricioaniche/83a9b17ad588b37d9431 to your computer and use it in GitHub Desktop.
Revisions
-
mauricioaniche created this gist
Jan 26, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ #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 hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ void alocamapa(); void lemapa(); void liberamapa(); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ 5 10 |--------| |...|..-.| |..-|.@..| |......-.| |--------|