Skip to content

Instantly share code, notes, and snippets.

@mauricioaniche
Created January 26, 2015 20:19
Show Gist options
  • Save mauricioaniche/83a9b17ad588b37d9431 to your computer and use it in GitHub Desktop.
Save mauricioaniche/83a9b17ad588b37d9431 to your computer and use it in GitHub Desktop.
Foge Foge - Matriz - Final
#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();
}
void alocamapa();
void lemapa();
void liberamapa();
5 10
|--------|
|...|..-.|
|..-|.@..|
|......-.|
|--------|
@AlcyoneCesar
Copy link

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