Translation
-
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?
-
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?
did yo try "%03d"
-
did yo try "%03d"
-
OK, How about "%.2d" - This will print a leading zero before any decimal
-
OK, How about "%.2d" - This will print a leading zero before any decimal
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); }
-
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?
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 : 260Is 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 : 090sprintf(Tempcrap1, "%03d", (Modi[i] - 48) * 10);
-
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 : 260Is 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 : 090sprintf(Tempcrap1, "%03d", (Modi[i] - 48) * 10);
-
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 : 260Is 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 : 090sprintf(Tempcrap1, "%03d", (Modi[i] - 48) * 10);
-
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"
-
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"
-
"input data goes here" : "output data goes here" A : 010 B : 020 C : 030 D : 040 ............... Z : 026 Y : 025
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 -
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 026I 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
-
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
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.
-
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.
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:
-
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:
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);
-
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);
-
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
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 -
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 -
I do not need to produce for 7 a leading 0. In this case should be Z-260 and rest of the string.
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.