Created
November 23, 2018 20:31
-
-
Save leorcvargas/e474538ed8a8d7292947a08cd828d9da to your computer and use it in GitHub Desktop.
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
int sizeX; | |
int sizeY; | |
char linha[50]; | |
FILE *fp; | |
fp = fopen("img.txt", "r"); | |
if (fp == NULL) | |
{ | |
perror("Read error"); | |
exit(EXIT_FAILURE); | |
} | |
fscanf(fp, "%d %d", &sizeX, &sizeY); | |
int **malha = NULL; | |
malha = (int **)malloc(sizeX * sizeof(int *)); | |
int i; | |
for (i = 0; i < sizeX; i++) | |
{ | |
malha[i] = (int *)malloc(sizeY * sizeof(int)); | |
} | |
char ponto; | |
int x = 0; | |
int y = 0; | |
while ((ponto = fgetc(fp)) != EOF) | |
{ | |
if (ponto != ' ' && ponto != '\n') | |
{ | |
switch (ponto) | |
{ | |
case '1': | |
malha[x][y] = 1; | |
break; | |
case '0': | |
malha[x][y] = 0; | |
break; | |
} | |
y++; | |
if (y == sizeY) | |
{ | |
y = 0; | |
x++; | |
} | |
if (x == sizeX) | |
{ | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment