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. Translation

Translation

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
19 Posts 3 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.
  • S Offline
    S Offline
    sardinka
    wrote on last edited by
    #1

    I have the following line in my code: sprintf(Tempcrap1, "%02d", Modi[i] - 64); strcat(Tempcrap, Tempcrap1); Where I am translating the alpha to numeric: A-010,b-020,c-030 .... for some reason I am loosing 0 after the numbers. My result is:a-01,b-02,c-03... Where is the error?

    S D 2 Replies Last reply
    0
    • S sardinka

      I have the following line in my code: sprintf(Tempcrap1, "%02d", Modi[i] - 64); strcat(Tempcrap, Tempcrap1); Where I am translating the alpha to numeric: A-010,b-020,c-030 .... for some reason I am loosing 0 after the numbers. My result is:a-01,b-02,c-03... Where is the error?

      S Offline
      S Offline
      Shay Harel
      wrote on last edited by
      #2

      did yo try "%03d"

      S 1 Reply Last reply
      0
      • S Shay Harel

        did yo try "%03d"

        S Offline
        S Offline
        sardinka
        wrote on last edited by
        #3

        yes. It gives me 007.Instead of 070.

        S 1 Reply Last reply
        0
        • S sardinka

          yes. It gives me 007.Instead of 070.

          S Offline
          S Offline
          Shay Harel
          wrote on last edited by
          #4

          OK, How about "%.2d" - This will print a leading zero before any decimal

          S 1 Reply Last reply
          0
          • S Shay Harel

            OK, How about "%.2d" - This will print a leading zero before any decimal

            S Offline
            S Offline
            sardinka
            wrote on last edited by
            #5

            Below my proc. where I am translating value. Case when Numeric,numeric,alpha: is fine. Case when Alpha,numeric,numeric is incorrect. Example:G73-07013 but my program transalted to 00773. A-010,b-020,c-030 etc. int convert_char_modifier_new(char *Modifier, char *NewModifier) {/* Convert Modifier value from alpha to numeric */ char NewMod2[8]; char Tempcrap[8]; char Tempcrap1[8]; char Tempcrap2[8]; memset(NewMod2,0x00,sizeof(NewMod2)); memset(Tempcrap,0x00,sizeof(Tempcrap)); memset(Tempcrap1,0x00,sizeof(Tempcrap1)); unsigned int i; for ( i = 0; i < strlen(Modifier); i++ ) { if (isdigit(Modifier[i])) { sprintf(Tempcrap1, "%d", Modifier[i] - 48); strcat(Tempcrap, Tempcrap1); } else { sprintf(Tempcrap1, "%02d", Modifier[i] - 64); strcat(Tempcrap, Tempcrap1); } } sprintf(NewMod2, "%03s", Tempcrap); strcat(NewModifier, NewMod2); return(0); }

            1 Reply Last reply
            0
            • S sardinka

              I have the following line in my code: sprintf(Tempcrap1, "%02d", Modi[i] - 64); strcat(Tempcrap, Tempcrap1); Where I am translating the alpha to numeric: A-010,b-020,c-030 .... for some reason I am loosing 0 after the numbers. My result is:a-01,b-02,c-03... Where is the error?

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              I'm not sure I understand your input/output. From what I gather you are wanting something like this for letters:

              Input : Output
              A : 010
              B : 020
              C : 030
              D : 040
              ...
              Y : 250
              Z : 260

              Is that right? If so, this should work: sprintf(Tempcrap1, "%03d", (Modi[i] - 64) * 10); If the input contains numbers, like:

              Input : Output
              0 : 000
              1 : 010
              2 : 020
              3 : 030
              ...
              8 : 080
              9 : 090

              sprintf(Tempcrap1, "%03d", (Modi[i] - 48) * 10);

              S 2 Replies Last reply
              0
              • D David Crow

                I'm not sure I understand your input/output. From what I gather you are wanting something like this for letters:

                Input : Output
                A : 010
                B : 020
                C : 030
                D : 040
                ...
                Y : 250
                Z : 260

                Is that right? If so, this should work: sprintf(Tempcrap1, "%03d", (Modi[i] - 64) * 10); If the input contains numbers, like:

                Input : Output
                0 : 000
                1 : 010
                2 : 020
                3 : 030
                ...
                8 : 080
                9 : 090

                sprintf(Tempcrap1, "%03d", (Modi[i] - 48) * 10);

                S Offline
                S Offline
                sardinka
                wrote on last edited by
                #7

                Thank you for reply. The problem is when input : Output A 10 B 20 C 30 ........... Y 25 Z 26 I am missing 0 if number 10,20,30,...90.

                1 Reply Last reply
                0
                • D David Crow

                  I'm not sure I understand your input/output. From what I gather you are wanting something like this for letters:

                  Input : Output
                  A : 010
                  B : 020
                  C : 030
                  D : 040
                  ...
                  Y : 250
                  Z : 260

                  Is that right? If so, this should work: sprintf(Tempcrap1, "%03d", (Modi[i] - 64) * 10); If the input contains numbers, like:

                  Input : Output
                  0 : 000
                  1 : 010
                  2 : 020
                  3 : 030
                  ...
                  8 : 080
                  9 : 090

                  sprintf(Tempcrap1, "%03d", (Modi[i] - 48) * 10);

                  S Offline
                  S Offline
                  sardinka
                  wrote on last edited by
                  #8

                  my problem is I need to have this value at the end: A-10 b-20 c-30 ... y-25 x-26

                  D 1 Reply Last reply
                  0
                  • S sardinka

                    my problem is I need to have this value at the end: A-10 b-20 c-30 ... y-25 x-26

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    At the end of what? I've yet to determine what you are considering input and what you are considering output. Do something simple like: When my program sees input like "input data goes here", I want the output to be "output data goes here"

                    S 1 Reply Last reply
                    0
                    • D David Crow

                      At the end of what? I've yet to determine what you are considering input and what you are considering output. Do something simple like: When my program sees input like "input data goes here", I want the output to be "output data goes here"

                      S Offline
                      S Offline
                      sardinka
                      wrote on last edited by
                      #10

                      "input data goes here" : "output data goes here" A : 010 B : 020 C : 030 D : 040 ............... Z : 026 Y : 025

                      D 1 Reply Last reply
                      0
                      • S sardinka

                        "input data goes here" : "output data goes here" A : 010 B : 020 C : 030 D : 040 ............... Z : 026 Y : 025

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #11

                        This won't work. See the problem?

                        A 010 N 014
                        B 020 O 015
                        C 030 P 016
                        D 040 Q 017
                        E 050 R 018
                        F 060 S 019
                        G 070 T 020
                        H 080 U 021
                        I 090 V 022
                        J 010 W 023
                        K 011 X 024
                        L 012 Y 025
                        M 013 Z 026

                        S 1 Reply Last reply
                        0
                        • D David Crow

                          This won't work. See the problem?

                          A 010 N 014
                          B 020 O 015
                          C 030 P 016
                          D 040 Q 017
                          E 050 R 018
                          F 060 S 019
                          G 070 T 020
                          H 080 U 021
                          I 090 V 022
                          J 010 W 023
                          K 011 X 024
                          L 012 Y 025
                          M 013 Z 026

                          S Offline
                          S Offline
                          sardinka
                          wrote on last edited by
                          #12

                          I am so sorry. I mistype::(( it should look like this: A 010 N 140 B 020 O 150 C 030 P 160 D 040 Q 170 E 050 R 180 F 060 S 190 G 070 T 200 H 080 U 210 I 090 V 220 J 100 W 230 K110 X 240 L 120 Y 250 M130 Z 260 My output should be: A 10 N 14 B 20 O 15 C 30 P 16 D 40 Q 17 E 50 R 18 F 60 S 19 G70 T 20 H80 U 21 I 90 V 22 J10 W 23 K11 X 24 L 12 Y 25 M13 Z 26

                          D 1 Reply Last reply
                          0
                          • S sardinka

                            I am so sorry. I mistype::(( it should look like this: A 010 N 140 B 020 O 150 C 030 P 160 D 040 Q 170 E 050 R 180 F 060 S 190 G 070 T 200 H 080 U 210 I 090 V 220 J 100 W 230 K110 X 240 L 120 Y 250 M130 Z 260 My output should be: A 10 N 14 B 20 O 15 C 30 P 16 D 40 Q 17 E 50 R 18 F 60 S 19 G70 T 20 H80 U 21 I 90 V 22 J10 W 23 K11 X 24 L 12 Y 25 M13 Z 26

                            D Offline
                            D Offline
                            David Crow
                            wrote on last edited by
                            #13

                            You just can't make up your mind, can you? First you state that "it should look like this" and show one table, and then you follow that with "my output should be" and show a completely different table. In the bottom table, do you not see the obvious error? A and J cannot both be 10.

                            S 1 Reply Last reply
                            0
                            • D David Crow

                              You just can't make up your mind, can you? First you state that "it should look like this" and show one table, and then you follow that with "my output should be" and show a completely different table. In the bottom table, do you not see the obvious error? A and J cannot both be 10.

                              S Offline
                              S Offline
                              sardinka
                              wrote on last edited by
                              #14

                              Now I understand what you are saying. I am appreciated for your patient. I am just learning C++, so I am not seeing full picture at first. My project is to translate from alpha to numeric starting with the A=10 increase the next letter by 10 and then delete zero before numbers. I got it to work but I am missing zero after the number if number=10…90. What would you recommended to do with the J? :confused:

                              D 1 Reply Last reply
                              0
                              • S sardinka

                                Now I understand what you are saying. I am appreciated for your patient. I am just learning C++, so I am not seeing full picture at first. My project is to translate from alpha to numeric starting with the A=10 increase the next letter by 10 and then delete zero before numbers. I got it to work but I am missing zero after the number if number=10…90. What would you recommended to do with the J? :confused:

                                D Offline
                                D Offline
                                David Crow
                                wrote on last edited by
                                #15

                                sardinka wrote: My project is to translate from alpha to numeric starting with the A=10 increase the next letter by 10 and then delete zero before numbers. This will do exactly that: sprintf(Tempcrap1, "%d", (Modi[i] - 64) * 10);

                                S 1 Reply Last reply
                                0
                                • D David Crow

                                  sardinka wrote: My project is to translate from alpha to numeric starting with the A=10 increase the next letter by 10 and then delete zero before numbers. This will do exactly that: sprintf(Tempcrap1, "%d", (Modi[i] - 64) * 10);

                                  S Offline
                                  S Offline
                                  sardinka
                                  wrote on last edited by
                                  #16

                                  I copyed your line of code into my program. here my output(what I am getting). Examples: Entered Value:Should be : :((I am getting 9AB : 90102 : 91020 Z73 : 26073 : 26073 9ZY : 92625 : 9260250

                                  D 1 Reply Last reply
                                  0
                                  • S sardinka

                                    I copyed your line of code into my program. here my output(what I am getting). Examples: Entered Value:Should be : :((I am getting 9AB : 90102 : 91020 Z73 : 26073 : 26073 9ZY : 92625 : 9260250

                                    D Offline
                                    D Offline
                                    David Crow
                                    wrote on last edited by
                                    #17

                                    There are still discrepancies. For example, when Z73 is input, you want (and are getting) 26073 as output. Assuming the 26 is for the Z, why does the 7 get a leading 0 but the 3 does not? Use: sprintf(Tempcrap1, "%02d", Modi[i] - 64); when converting letters to numbers, and: sprintf(Tempcrap1, "%d", Modi[i] - 48); otherwise. This will produce:

                                    Input : Output
                                    9AB : 90102
                                    Z73 : 260703
                                    9ZY : 92625

                                    S 1 Reply Last reply
                                    0
                                    • D David Crow

                                      There are still discrepancies. For example, when Z73 is input, you want (and are getting) 26073 as output. Assuming the 26 is for the Z, why does the 7 get a leading 0 but the 3 does not? Use: sprintf(Tempcrap1, "%02d", Modi[i] - 64); when converting letters to numbers, and: sprintf(Tempcrap1, "%d", Modi[i] - 48); otherwise. This will produce:

                                      Input : Output
                                      9AB : 90102
                                      Z73 : 260703
                                      9ZY : 92625

                                      S Offline
                                      S Offline
                                      sardinka
                                      wrote on last edited by
                                      #18

                                      I do not need to produce for 7 a leading 0. In this case should be Z-260 and rest of the string.

                                      D 1 Reply Last reply
                                      0
                                      • S sardinka

                                        I do not need to produce for 7 a leading 0. In this case should be Z-260 and rest of the string.

                                        D Offline
                                        D Offline
                                        David Crow
                                        wrote on last edited by
                                        #19

                                        Do you not find it odd that each time you state what you want, it's different from the time before? Has anyone ever told you it's very difficult to hit a moving target? In this latest post, you want "260" to be the output for "Z", yet in the previous post (i.e., "9ZY : 92625 : 9260250"), you want "26" to be the output for "Z". I think it's time you step back and better define your requirements.

                                        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