Hi,
Say,my data is as follows:
+1
+2
-3
+4
-5
What I want to do is following:
I want to write a reverse function that will look like:
reverse (char *data[],pos1,pos2)
An example to illustrate this fn is:
Say I call reverse (data,0,3).
Then my o/p will be +3 -2 -1 +4 -5 i.e. it will not only reverse the digits between the 2 positions but also the signs.
Firstly I'm trying this with what if pos2-pos1 =1 then I need to change the sign of only data[pos2][0]. I'm writing:
But strangely even if I check that the difference is 1 the fn is not entering the if loop!!!Code:if (abs(pos2-pos1)==1) { if(data[pos1][0]=='+') data[pos1][0]=='-'; else data[pos1][0]=='+'; }
Any idea why this can happen?
Also what should be a better approach (so that I dont need to consider the difference = 1 case)
Appreciate your guidance.
Thanks,
Angkar