Replace values
-
Hi all, I am reading some values from command line and i want to replace them with other values. Command line input ranges are from (50,51,52,........... 480,481,482) I need to replace with (172,171,.....0,-1,-2,...-260) Here is my code:
int main(int argn, char **argv)
{
char c;
int h;
double Pos[9];
double pd[6];
double test=51;
printf("\nEnter position (val1, val2,val3,val4,val5,val6,val7,val8,val9):\n");for(h=0; h<9; h++) scanf("%lf",&Pos\[h\]); if(Pos\[7\]=="50") Pos\[7\]=172 if(Pos\[7\]=="51") Pos\[7\]=171; if(Pos\[7\]=="52") Pos\[7\]=170; return 1;
}
Can someone help me how to do. Thanks Raj
-
Hi all, I am reading some values from command line and i want to replace them with other values. Command line input ranges are from (50,51,52,........... 480,481,482) I need to replace with (172,171,.....0,-1,-2,...-260) Here is my code:
int main(int argn, char **argv)
{
char c;
int h;
double Pos[9];
double pd[6];
double test=51;
printf("\nEnter position (val1, val2,val3,val4,val5,val6,val7,val8,val9):\n");for(h=0; h<9; h++) scanf("%lf",&Pos\[h\]); if(Pos\[7\]=="50") Pos\[7\]=172 if(Pos\[7\]=="51") Pos\[7\]=171; if(Pos\[7\]=="52") Pos\[7\]=170; return 1;
}
Can someone help me how to do. Thanks Raj
I don't understand the details of your requirements, however for sure you must take advantage of the linear relationship between the input and the output range:
newValue = 222 - originalValue;
:)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Hi all, I am reading some values from command line and i want to replace them with other values. Command line input ranges are from (50,51,52,........... 480,481,482) I need to replace with (172,171,.....0,-1,-2,...-260) Here is my code:
int main(int argn, char **argv)
{
char c;
int h;
double Pos[9];
double pd[6];
double test=51;
printf("\nEnter position (val1, val2,val3,val4,val5,val6,val7,val8,val9):\n");for(h=0; h<9; h++) scanf("%lf",&Pos\[h\]); if(Pos\[7\]=="50") Pos\[7\]=172 if(Pos\[7\]=="51") Pos\[7\]=171; if(Pos\[7\]=="52") Pos\[7\]=170; return 1;
}
Can someone help me how to do. Thanks Raj
Your transformation law is
y = 222 - x
(y = 172 - (x-50)) Cannot you simply apply it to the input data?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi all, I am reading some values from command line and i want to replace them with other values. Command line input ranges are from (50,51,52,........... 480,481,482) I need to replace with (172,171,.....0,-1,-2,...-260) Here is my code:
int main(int argn, char **argv)
{
char c;
int h;
double Pos[9];
double pd[6];
double test=51;
printf("\nEnter position (val1, val2,val3,val4,val5,val6,val7,val8,val9):\n");for(h=0; h<9; h++) scanf("%lf",&Pos\[h\]); if(Pos\[7\]=="50") Pos\[7\]=172 if(Pos\[7\]=="51") Pos\[7\]=171; if(Pos\[7\]=="52") Pos\[7\]=170; return 1;
}
Can someone help me how to do. Thanks Raj
Don't use doubles for integer values, it will only cause you problems. As stated by both Luc and Carlo, you have a simple calculation to do on each input value, you can then store or output the new values as required.
Just say 'NO' to evaluated arguments for diadic functions! Ash
-
Hi all, I am reading some values from command line and i want to replace them with other values. Command line input ranges are from (50,51,52,........... 480,481,482) I need to replace with (172,171,.....0,-1,-2,...-260) Here is my code:
int main(int argn, char **argv)
{
char c;
int h;
double Pos[9];
double pd[6];
double test=51;
printf("\nEnter position (val1, val2,val3,val4,val5,val6,val7,val8,val9):\n");for(h=0; h<9; h++) scanf("%lf",&Pos\[h\]); if(Pos\[7\]=="50") Pos\[7\]=172 if(Pos\[7\]=="51") Pos\[7\]=171; if(Pos\[7\]=="52") Pos\[7\]=170; return 1;
}
Can someone help me how to do. Thanks Raj
Loop in X to Y, where X = first command line Value(Convered to Int) Y = Last command line Value (Converted to Int) output = Y - X - 260; Thanks Anand
Thanks, Anand.
-
Hi all, I am reading some values from command line and i want to replace them with other values. Command line input ranges are from (50,51,52,........... 480,481,482) I need to replace with (172,171,.....0,-1,-2,...-260) Here is my code:
int main(int argn, char **argv)
{
char c;
int h;
double Pos[9];
double pd[6];
double test=51;
printf("\nEnter position (val1, val2,val3,val4,val5,val6,val7,val8,val9):\n");for(h=0; h<9; h++) scanf("%lf",&Pos\[h\]); if(Pos\[7\]=="50") Pos\[7\]=172 if(Pos\[7\]=="51") Pos\[7\]=171; if(Pos\[7\]=="52") Pos\[7\]=170; return 1;
}
Can someone help me how to do. Thanks Raj
Apart from the fact that you could simplify the code as suggested by others, there are a number of immediate problems with this bit of code:
raju_shiva wrote:
if(Pos[7]=="50") Pos[7]=172
First, Pos[7] is a double - in C if you compare Pos[7] to "50", which is a null-terminated string not a numeric value, you will not get what you expect. That line should be:
if(Pos[7]==50)
Second, even with that change, it will almost certainly not work, because comparing floating-point value to an integer is unlikely ever to give a match. Change Pos to an array of integers instead. Third, you are missing the terminating semi-colon at the end of the next line, which should be:
Pos[7]=172;