Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Replace values

Replace values

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    raju_shiva
    wrote on last edited by
    #1

    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

    L C L A N 5 Replies Last reply
    0
    • R raju_shiva

      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

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • R raju_shiva

        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

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        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]

        1 Reply Last reply
        0
        • R raju_shiva

          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

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • R raju_shiva

            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

            A Offline
            A Offline
            Anand Todkar
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • R raju_shiva

              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

              N Offline
              N Offline
              normanS
              wrote on last edited by
              #6

              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;

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups