Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save leorcvargas/e474538ed8a8d7292947a08cd828d9da to your computer and use it in GitHub Desktop.
Save leorcvargas/e474538ed8a8d7292947a08cd828d9da to your computer and use it in GitHub Desktop.
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