You are missing a closing bracket before 'pel = array[4];'. Besides, accessing negative indices is not a good idea, I'm pretty sure it will crash your program.
You are missing a closing bracket before 'pel = array[4];'. Besides, accessing negative indices is not a good idea, I'm pretty sure it will crash your program.
Thanks so much for pointing that out, I've been spending hours on that, but couldn't spot that out.Originally Posted by Desolation
Is there a way of using "for" loop or some other loop to respresent this array, so that I can change the parameter of the median filter. At the moment, this is a 3x3 median filter. I would like program something can change its parameter, i.e. 3x3, 5x5, 7x7... 15x15 without reprogramming the source code.Code:char array[9]; array[0]=buf[-1][-1]; array[1]=buf[-1][0]; array[2]=buf[-1][1]; array[3]=buf[0][-1]; array[4]=buf[0][0]; array[5]=buf[0][1]; array[6]=buf[1][-1]; array[7]=buf[1][0]; array[8]=buf[1][1];
You'd probably need nested for loops of depth two.
And yes, negative indices aren't a really good idea.Code:for(i) // each row { for(j) // each element in the current row { array[i * width + j] //this is the corresponding element } }
Code:#include <stdio.h> void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){ puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9 /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i] ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][ t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}
Sorry, I forgot to mention in the first post that the class library "picture.h" allows "pel"'s to use negative indices for neighbourhood operators, i.e. buf[-1][-1] is the top left corner of the centre pixel. But this only apply to the functions which use pel only.Originally Posted by jafet
This method is been great help, thanks!You'd probably need nested for loops of depth two.