It's pretty straightforward, but i'm getting an invalid memory reference.
however, i checked (by doing infinite loops), and i'm pretty sure
it's not referencing outside the p[33][33] array, or off the end of the
tree[1024] strings.
Here's the code:
Code: Select all
#include <stdio.h>
int p[2][33][33];
int index;
void color (int n, char *str, int size, int x, int y) {
int i,j;
if (str[index] == 'p') {
index++;
color(n, str, size/2, x+size/2, y);
color(n, str, size/2, x, y);
color(n, str, size/2, x, y+size/2);
color(n, str, size/2, x+size/2, y+size/2);
}
else if (str[index] == 'f') {
index++;
for (i=y; i<y+size; i++) {
for (j=x; j<x+size; j++) {
p[n][i][j] = 1;
}
}
}
else index++;
}
int main () {
int num,i,j,c,x,total;
char tree[1024], tree2[1024];
double a;
scanf("%d\n", &num);
for (i=0; i<num; i++) {
scanf("%s\n%s\n", tree, tree2);
memset(p,0,sizeof(p));
index=0;
color(0, tree, 32, 0, 0);
index=0;
color(1, tree2, 32, 0, 0);
total=0;
for (j=0; j<32; j++) {
for (c=0; c<32; c++) {
x = p[0][j][c] | p[1][j][c];
if (x) total++;
}
}
printf("There are %d black pixels.\n", total);
}
return 0;
}
doing anything else, i get an invalid memory reference.
It seems to me like the input file is corrupted. anybody else have the
same problem, or am i just doing something extremely dumb?

Thanks for any input