I have a C program where I have to change a 2D array into a 1D array.
What I want is to change this code:
temp[i][j] = (Grid[i][j-1] + Grid[i][j] + Grid[i+1][j] + Grid[i][j+1])/5
to this one:
temp[i*PPE+j] = (Grid[i*PPE+j-1] + Grid[i*PPE+j] + Grid[(i+1)*PPE+j] + Grid[i*PPE+j+1])/5
Because I'm new to Vimscript I split the problem into two parts and tried to tackle the first one:
[i][j]
->[i*PPE+j]
[i+1][j+1]
->[(i+1)*PPE+j+1]
I tried the following until now:
:%s#\v[^0-9](\]\[)[a-z][^-+]#\=substitute("\1","*PPE+", "", "")#gc
My reasoning behind this:
:%s#\v
: go through whole file and use magic[^0-9](\]\[)[a-z][^-+]
: match<nonumber>][<char><not+or->
and () for establishing a group\=substitute("\1","*PPE+", "", "")
: substitute the first group (][
) with *PPE+gc
:g
for all matches in one line andc
for confirmation query
Unfortunately this doesn't seem to work as it replaces i][j]
with ^A
Any help with this would be greatly appreciated!
sub-replace-specials
ie.\1
after\=
. This should besubmatch(1)
. This is mentioned under:h sub-replace-expression
.[i][j]
with[][